xref: /dragonfly/contrib/gcc-8.0/gcc/c/c-decl.c (revision 58e805e6)
138fd1498Szrj /* Process declarations and variables for C compiler.
238fd1498Szrj    Copyright (C) 1988-2018 Free Software Foundation, Inc.
338fd1498Szrj 
438fd1498Szrj This file is part of GCC.
538fd1498Szrj 
638fd1498Szrj GCC is free software; you can redistribute it and/or modify it under
738fd1498Szrj the terms of the GNU General Public License as published by the Free
838fd1498Szrj Software Foundation; either version 3, or (at your option) any later
938fd1498Szrj version.
1038fd1498Szrj 
1138fd1498Szrj GCC is distributed in the hope that it will be useful, but WITHOUT ANY
1238fd1498Szrj WARRANTY; without even the implied warranty of MERCHANTABILITY or
1338fd1498Szrj FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1438fd1498Szrj for more details.
1538fd1498Szrj 
1638fd1498Szrj You should have received a copy of the GNU General Public License
1738fd1498Szrj along with GCC; see the file COPYING3.  If not see
1838fd1498Szrj <http://www.gnu.org/licenses/>.  */
1938fd1498Szrj 
2038fd1498Szrj /* Process declarations and symbol lookup for C front end.
2138fd1498Szrj    Also constructs types; the standard scalar types at initialization,
2238fd1498Szrj    and structure, union, array and enum types when they are declared.  */
2338fd1498Szrj 
2438fd1498Szrj /* ??? not all decl nodes are given the most useful possible
2538fd1498Szrj    line numbers.  For example, the CONST_DECLs for enum values.  */
2638fd1498Szrj 
2738fd1498Szrj #include "config.h"
2838fd1498Szrj #define INCLUDE_UNIQUE_PTR
2938fd1498Szrj #include "system.h"
3038fd1498Szrj #include "coretypes.h"
3138fd1498Szrj #include "target.h"
3238fd1498Szrj #include "function.h"
3338fd1498Szrj #include "c-tree.h"
3438fd1498Szrj #include "timevar.h"
3538fd1498Szrj #include "stringpool.h"
3638fd1498Szrj #include "cgraph.h"
3738fd1498Szrj #include "intl.h"
3838fd1498Szrj #include "print-tree.h"
3938fd1498Szrj #include "stor-layout.h"
4038fd1498Szrj #include "varasm.h"
4138fd1498Szrj #include "attribs.h"
4238fd1498Szrj #include "toplev.h"
4338fd1498Szrj #include "debug.h"
4438fd1498Szrj #include "c-family/c-objc.h"
4538fd1498Szrj #include "c-family/c-pragma.h"
4638fd1498Szrj #include "c-family/c-ubsan.h"
4738fd1498Szrj #include "c-lang.h"
4838fd1498Szrj #include "langhooks.h"
4938fd1498Szrj #include "tree-iterator.h"
5038fd1498Szrj #include "dumpfile.h"
5138fd1498Szrj #include "plugin.h"
5238fd1498Szrj #include "c-family/c-ada-spec.h"
5338fd1498Szrj #include "builtins.h"
5438fd1498Szrj #include "spellcheck-tree.h"
5538fd1498Szrj #include "gcc-rich-location.h"
5638fd1498Szrj #include "asan.h"
5738fd1498Szrj #include "c-family/name-hint.h"
5838fd1498Szrj #include "c-family/known-headers.h"
5938fd1498Szrj #include "c-family/c-spellcheck.h"
6038fd1498Szrj 
6138fd1498Szrj /* In grokdeclarator, distinguish syntactic contexts of declarators.  */
6238fd1498Szrj enum decl_context
6338fd1498Szrj { NORMAL,			/* Ordinary declaration */
6438fd1498Szrj   FUNCDEF,			/* Function definition */
6538fd1498Szrj   PARM,				/* Declaration of parm before function body */
6638fd1498Szrj   FIELD,			/* Declaration inside struct or union */
6738fd1498Szrj   TYPENAME};			/* Typename (inside cast or sizeof)  */
6838fd1498Szrj 
6938fd1498Szrj /* States indicating how grokdeclarator() should handle declspecs marked
7038fd1498Szrj    with __attribute__((deprecated)).  An object declared as
7138fd1498Szrj    __attribute__((deprecated)) suppresses warnings of uses of other
7238fd1498Szrj    deprecated items.  */
7338fd1498Szrj 
7438fd1498Szrj enum deprecated_states {
7538fd1498Szrj   DEPRECATED_NORMAL,
7638fd1498Szrj   DEPRECATED_SUPPRESS
7738fd1498Szrj };
7838fd1498Szrj 
7938fd1498Szrj 
8038fd1498Szrj /* Nonzero if we have seen an invalid cross reference
8138fd1498Szrj    to a struct, union, or enum, but not yet printed the message.  */
8238fd1498Szrj tree pending_invalid_xref;
8338fd1498Szrj 
8438fd1498Szrj /* File and line to appear in the eventual error message.  */
8538fd1498Szrj location_t pending_invalid_xref_location;
8638fd1498Szrj 
8738fd1498Szrj /* The file and line that the prototype came from if this is an
8838fd1498Szrj    old-style definition; used for diagnostics in
8938fd1498Szrj    store_parm_decls_oldstyle.  */
9038fd1498Szrj 
9138fd1498Szrj static location_t current_function_prototype_locus;
9238fd1498Szrj 
9338fd1498Szrj /* Whether this prototype was built-in.  */
9438fd1498Szrj 
9538fd1498Szrj static bool current_function_prototype_built_in;
9638fd1498Szrj 
9738fd1498Szrj /* The argument type information of this prototype.  */
9838fd1498Szrj 
9938fd1498Szrj static tree current_function_prototype_arg_types;
10038fd1498Szrj 
10138fd1498Szrj /* The argument information structure for the function currently being
10238fd1498Szrj    defined.  */
10338fd1498Szrj 
10438fd1498Szrj static struct c_arg_info *current_function_arg_info;
10538fd1498Szrj 
10638fd1498Szrj /* The obstack on which parser and related data structures, which are
10738fd1498Szrj    not live beyond their top-level declaration or definition, are
10838fd1498Szrj    allocated.  */
10938fd1498Szrj struct obstack parser_obstack;
11038fd1498Szrj 
11138fd1498Szrj /* The current statement tree.  */
11238fd1498Szrj 
11338fd1498Szrj static GTY(()) struct stmt_tree_s c_stmt_tree;
11438fd1498Szrj 
11538fd1498Szrj /* State saving variables.  */
11638fd1498Szrj tree c_break_label;
11738fd1498Szrj tree c_cont_label;
11838fd1498Szrj 
11938fd1498Szrj /* A list of decls to be made automatically visible in each file scope.  */
12038fd1498Szrj static GTY(()) tree visible_builtins;
12138fd1498Szrj 
12238fd1498Szrj /* Set to 0 at beginning of a function definition, set to 1 if
12338fd1498Szrj    a return statement that specifies a return value is seen.  */
12438fd1498Szrj 
12538fd1498Szrj int current_function_returns_value;
12638fd1498Szrj 
12738fd1498Szrj /* Set to 0 at beginning of a function definition, set to 1 if
12838fd1498Szrj    a return statement with no argument is seen.  */
12938fd1498Szrj 
13038fd1498Szrj int current_function_returns_null;
13138fd1498Szrj 
13238fd1498Szrj /* Set to 0 at beginning of a function definition, set to 1 if
13338fd1498Szrj    a call to a noreturn function is seen.  */
13438fd1498Szrj 
13538fd1498Szrj int current_function_returns_abnormally;
13638fd1498Szrj 
13738fd1498Szrj /* Set to nonzero by `grokdeclarator' for a function
13838fd1498Szrj    whose return type is defaulted, if warnings for this are desired.  */
13938fd1498Szrj 
14038fd1498Szrj static int warn_about_return_type;
14138fd1498Szrj 
14238fd1498Szrj /* Nonzero when the current toplevel function contains a declaration
14338fd1498Szrj    of a nested function which is never defined.  */
14438fd1498Szrj 
14538fd1498Szrj static bool undef_nested_function;
14638fd1498Szrj 
14738fd1498Szrj /* If non-zero, implicit "omp declare target" attribute is added into the
14838fd1498Szrj    attribute lists.  */
14938fd1498Szrj int current_omp_declare_target_attribute;
15038fd1498Szrj 
15138fd1498Szrj /* Each c_binding structure describes one binding of an identifier to
15238fd1498Szrj    a decl.  All the decls in a scope - irrespective of namespace - are
15338fd1498Szrj    chained together by the ->prev field, which (as the name implies)
15438fd1498Szrj    runs in reverse order.  All the decls in a given namespace bound to
15538fd1498Szrj    a given identifier are chained by the ->shadowed field, which runs
15638fd1498Szrj    from inner to outer scopes.
15738fd1498Szrj 
15838fd1498Szrj    The ->decl field usually points to a DECL node, but there are two
15938fd1498Szrj    exceptions.  In the namespace of type tags, the bound entity is a
16038fd1498Szrj    RECORD_TYPE, UNION_TYPE, or ENUMERAL_TYPE node.  If an undeclared
16138fd1498Szrj    identifier is encountered, it is bound to error_mark_node to
16238fd1498Szrj    suppress further errors about that identifier in the current
16338fd1498Szrj    function.
16438fd1498Szrj 
16538fd1498Szrj    The ->u.type field stores the type of the declaration in this scope;
16638fd1498Szrj    if NULL, the type is the type of the ->decl field.  This is only of
16738fd1498Szrj    relevance for objects with external or internal linkage which may
16838fd1498Szrj    be redeclared in inner scopes, forming composite types that only
16938fd1498Szrj    persist for the duration of those scopes.  In the external scope,
17038fd1498Szrj    this stores the composite of all the types declared for this
17138fd1498Szrj    object, visible or not.  The ->inner_comp field (used only at file
17238fd1498Szrj    scope) stores whether an incomplete array type at file scope was
17338fd1498Szrj    completed at an inner scope to an array size other than 1.
17438fd1498Szrj 
17538fd1498Szrj    The ->u.label field is used for labels.  It points to a structure
17638fd1498Szrj    which stores additional information used for warnings.
17738fd1498Szrj 
17838fd1498Szrj    The depth field is copied from the scope structure that holds this
17938fd1498Szrj    decl.  It is used to preserve the proper ordering of the ->shadowed
18038fd1498Szrj    field (see bind()) and also for a handful of special-case checks.
18138fd1498Szrj    Finally, the invisible bit is true for a decl which should be
18238fd1498Szrj    ignored for purposes of normal name lookup, and the nested bit is
18338fd1498Szrj    true for a decl that's been bound a second time in an inner scope;
18438fd1498Szrj    in all such cases, the binding in the outer scope will have its
18538fd1498Szrj    invisible bit true.  */
18638fd1498Szrj 
18738fd1498Szrj struct GTY((chain_next ("%h.prev"))) c_binding {
18838fd1498Szrj   union GTY(()) {		/* first so GTY desc can use decl */
18938fd1498Szrj     tree GTY((tag ("0"))) type; /* the type in this scope */
19038fd1498Szrj     struct c_label_vars * GTY((tag ("1"))) label; /* for warnings */
19138fd1498Szrj   } GTY((desc ("TREE_CODE (%0.decl) == LABEL_DECL"))) u;
19238fd1498Szrj   tree decl;			/* the decl bound */
19338fd1498Szrj   tree id;			/* the identifier it's bound to */
19438fd1498Szrj   struct c_binding *prev;	/* the previous decl in this scope */
19538fd1498Szrj   struct c_binding *shadowed;	/* the innermost decl shadowed by this one */
19638fd1498Szrj   unsigned int depth : 28;      /* depth of this scope */
19738fd1498Szrj   BOOL_BITFIELD invisible : 1;  /* normal lookup should ignore this binding */
19838fd1498Szrj   BOOL_BITFIELD nested : 1;     /* do not set DECL_CONTEXT when popping */
19938fd1498Szrj   BOOL_BITFIELD inner_comp : 1; /* incomplete array completed in inner scope */
20038fd1498Szrj   BOOL_BITFIELD in_struct : 1;	/* currently defined as struct field */
20138fd1498Szrj   location_t locus;		/* location for nested bindings */
20238fd1498Szrj };
20338fd1498Szrj #define B_IN_SCOPE(b1, b2) ((b1)->depth == (b2)->depth)
20438fd1498Szrj #define B_IN_CURRENT_SCOPE(b) ((b)->depth == current_scope->depth)
20538fd1498Szrj #define B_IN_FILE_SCOPE(b) ((b)->depth == 1 /*file_scope->depth*/)
20638fd1498Szrj #define B_IN_EXTERNAL_SCOPE(b) ((b)->depth == 0 /*external_scope->depth*/)
20738fd1498Szrj 
20838fd1498Szrj /* Each C symbol points to three linked lists of c_binding structures.
20938fd1498Szrj    These describe the values of the identifier in the three different
21038fd1498Szrj    namespaces defined by the language.  */
21138fd1498Szrj 
21238fd1498Szrj struct GTY(()) lang_identifier {
21338fd1498Szrj   struct c_common_identifier common_id;
21438fd1498Szrj   struct c_binding *symbol_binding; /* vars, funcs, constants, typedefs */
21538fd1498Szrj   struct c_binding *tag_binding;    /* struct/union/enum tags */
21638fd1498Szrj   struct c_binding *label_binding;  /* labels */
21738fd1498Szrj };
21838fd1498Szrj 
21938fd1498Szrj /* Validate c-lang.c's assumptions.  */
22038fd1498Szrj extern char C_SIZEOF_STRUCT_LANG_IDENTIFIER_isnt_accurate
22138fd1498Szrj [(sizeof(struct lang_identifier) == C_SIZEOF_STRUCT_LANG_IDENTIFIER) ? 1 : -1];
22238fd1498Szrj 
22338fd1498Szrj /* The binding oracle; see c-tree.h.  */
22438fd1498Szrj void (*c_binding_oracle) (enum c_oracle_request, tree identifier);
22538fd1498Szrj 
22638fd1498Szrj /* This flag is set on an identifier if we have previously asked the
22738fd1498Szrj    binding oracle for this identifier's symbol binding.  */
22838fd1498Szrj #define I_SYMBOL_CHECKED(node) \
22938fd1498Szrj   (TREE_LANG_FLAG_4 (IDENTIFIER_NODE_CHECK (node)))
23038fd1498Szrj 
23138fd1498Szrj static inline struct c_binding* *
i_symbol_binding(tree node)23238fd1498Szrj i_symbol_binding (tree node)
23338fd1498Szrj {
23438fd1498Szrj   struct lang_identifier *lid
23538fd1498Szrj     = (struct lang_identifier *) IDENTIFIER_NODE_CHECK (node);
23638fd1498Szrj 
23738fd1498Szrj   if (lid->symbol_binding == NULL
23838fd1498Szrj       && c_binding_oracle != NULL
23938fd1498Szrj       && !I_SYMBOL_CHECKED (node))
24038fd1498Szrj     {
24138fd1498Szrj       /* Set the "checked" flag first, to avoid infinite recursion
24238fd1498Szrj 	 when the binding oracle calls back into gcc.  */
24338fd1498Szrj       I_SYMBOL_CHECKED (node) = 1;
24438fd1498Szrj       c_binding_oracle (C_ORACLE_SYMBOL, node);
24538fd1498Szrj     }
24638fd1498Szrj 
24738fd1498Szrj   return &lid->symbol_binding;
24838fd1498Szrj }
24938fd1498Szrj 
25038fd1498Szrj #define I_SYMBOL_BINDING(node) (*i_symbol_binding (node))
25138fd1498Szrj 
25238fd1498Szrj #define I_SYMBOL_DECL(node) \
25338fd1498Szrj  (I_SYMBOL_BINDING(node) ? I_SYMBOL_BINDING(node)->decl : 0)
25438fd1498Szrj 
25538fd1498Szrj /* This flag is set on an identifier if we have previously asked the
25638fd1498Szrj    binding oracle for this identifier's tag binding.  */
25738fd1498Szrj #define I_TAG_CHECKED(node) \
25838fd1498Szrj   (TREE_LANG_FLAG_5 (IDENTIFIER_NODE_CHECK (node)))
25938fd1498Szrj 
26038fd1498Szrj static inline struct c_binding **
i_tag_binding(tree node)26138fd1498Szrj i_tag_binding (tree node)
26238fd1498Szrj {
26338fd1498Szrj   struct lang_identifier *lid
26438fd1498Szrj     = (struct lang_identifier *) IDENTIFIER_NODE_CHECK (node);
26538fd1498Szrj 
26638fd1498Szrj   if (lid->tag_binding == NULL
26738fd1498Szrj       && c_binding_oracle != NULL
26838fd1498Szrj       && !I_TAG_CHECKED (node))
26938fd1498Szrj     {
27038fd1498Szrj       /* Set the "checked" flag first, to avoid infinite recursion
27138fd1498Szrj 	 when the binding oracle calls back into gcc.  */
27238fd1498Szrj       I_TAG_CHECKED (node) = 1;
27338fd1498Szrj       c_binding_oracle (C_ORACLE_TAG, node);
27438fd1498Szrj     }
27538fd1498Szrj 
27638fd1498Szrj   return &lid->tag_binding;
27738fd1498Szrj }
27838fd1498Szrj 
27938fd1498Szrj #define I_TAG_BINDING(node) (*i_tag_binding (node))
28038fd1498Szrj 
28138fd1498Szrj #define I_TAG_DECL(node) \
28238fd1498Szrj  (I_TAG_BINDING(node) ? I_TAG_BINDING(node)->decl : 0)
28338fd1498Szrj 
28438fd1498Szrj /* This flag is set on an identifier if we have previously asked the
28538fd1498Szrj    binding oracle for this identifier's label binding.  */
28638fd1498Szrj #define I_LABEL_CHECKED(node) \
28738fd1498Szrj   (TREE_LANG_FLAG_6 (IDENTIFIER_NODE_CHECK (node)))
28838fd1498Szrj 
28938fd1498Szrj static inline struct c_binding **
i_label_binding(tree node)29038fd1498Szrj i_label_binding (tree node)
29138fd1498Szrj {
29238fd1498Szrj   struct lang_identifier *lid
29338fd1498Szrj     = (struct lang_identifier *) IDENTIFIER_NODE_CHECK (node);
29438fd1498Szrj 
29538fd1498Szrj   if (lid->label_binding == NULL
29638fd1498Szrj       && c_binding_oracle != NULL
29738fd1498Szrj       && !I_LABEL_CHECKED (node))
29838fd1498Szrj     {
29938fd1498Szrj       /* Set the "checked" flag first, to avoid infinite recursion
30038fd1498Szrj 	 when the binding oracle calls back into gcc.  */
30138fd1498Szrj       I_LABEL_CHECKED (node) = 1;
30238fd1498Szrj       c_binding_oracle (C_ORACLE_LABEL, node);
30338fd1498Szrj     }
30438fd1498Szrj 
30538fd1498Szrj   return &lid->label_binding;
30638fd1498Szrj }
30738fd1498Szrj 
30838fd1498Szrj #define I_LABEL_BINDING(node) (*i_label_binding (node))
30938fd1498Szrj 
31038fd1498Szrj #define I_LABEL_DECL(node) \
31138fd1498Szrj  (I_LABEL_BINDING(node) ? I_LABEL_BINDING(node)->decl : 0)
31238fd1498Szrj 
31338fd1498Szrj /* The resulting tree type.  */
31438fd1498Szrj 
31538fd1498Szrj union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
31638fd1498Szrj        chain_next ("(union lang_tree_node *) c_tree_chain_next (&%h.generic)"))) lang_tree_node
31738fd1498Szrj  {
31838fd1498Szrj   union tree_node GTY ((tag ("0"),
31938fd1498Szrj 			desc ("tree_node_structure (&%h)")))
32038fd1498Szrj     generic;
32138fd1498Szrj   struct lang_identifier GTY ((tag ("1"))) identifier;
32238fd1498Szrj };
32338fd1498Szrj 
32438fd1498Szrj /* Track bindings and other things that matter for goto warnings.  For
32538fd1498Szrj    efficiency, we do not gather all the decls at the point of
32638fd1498Szrj    definition.  Instead, we point into the bindings structure.  As
32738fd1498Szrj    scopes are popped, we update these structures and gather the decls
32838fd1498Szrj    that matter at that time.  */
32938fd1498Szrj 
33038fd1498Szrj struct GTY(()) c_spot_bindings {
33138fd1498Szrj   /* The currently open scope which holds bindings defined when the
33238fd1498Szrj      label was defined or the goto statement was found.  */
33338fd1498Szrj   struct c_scope *scope;
33438fd1498Szrj   /* The bindings in the scope field which were defined at the point
33538fd1498Szrj      of the label or goto.  This lets us look at older or newer
33638fd1498Szrj      bindings in the scope, as appropriate.  */
33738fd1498Szrj   struct c_binding *bindings_in_scope;
33838fd1498Szrj   /* The number of statement expressions that have started since this
33938fd1498Szrj      label or goto statement was defined.  This is zero if we are at
34038fd1498Szrj      the same statement expression level.  It is positive if we are in
34138fd1498Szrj      a statement expression started since this spot.  It is negative
34238fd1498Szrj      if this spot was in a statement expression and we have left
34338fd1498Szrj      it.  */
34438fd1498Szrj   int stmt_exprs;
34538fd1498Szrj   /* Whether we started in a statement expression but are no longer in
34638fd1498Szrj      it.  This is set to true if stmt_exprs ever goes negative.  */
34738fd1498Szrj   bool left_stmt_expr;
34838fd1498Szrj };
34938fd1498Szrj 
35038fd1498Szrj /* This structure is used to keep track of bindings seen when a goto
35138fd1498Szrj    statement is defined.  This is only used if we see the goto
35238fd1498Szrj    statement before we see the label.  */
35338fd1498Szrj 
35438fd1498Szrj struct GTY(()) c_goto_bindings {
35538fd1498Szrj   /* The location of the goto statement.  */
35638fd1498Szrj   location_t loc;
35738fd1498Szrj   /* The bindings of the goto statement.  */
35838fd1498Szrj   struct c_spot_bindings goto_bindings;
35938fd1498Szrj };
36038fd1498Szrj 
36138fd1498Szrj typedef struct c_goto_bindings *c_goto_bindings_p;
36238fd1498Szrj 
36338fd1498Szrj /* The additional information we keep track of for a label binding.
36438fd1498Szrj    These fields are updated as scopes are popped.  */
36538fd1498Szrj 
36638fd1498Szrj struct GTY(()) c_label_vars {
36738fd1498Szrj   /* The shadowed c_label_vars, when one label shadows another (which
36838fd1498Szrj      can only happen using a __label__ declaration).  */
36938fd1498Szrj   struct c_label_vars *shadowed;
37038fd1498Szrj   /* The bindings when the label was defined.  */
37138fd1498Szrj   struct c_spot_bindings label_bindings;
37238fd1498Szrj   /* A list of decls that we care about: decls about which we should
37338fd1498Szrj      warn if a goto branches to this label from later in the function.
37438fd1498Szrj      Decls are added to this list as scopes are popped.  We only add
37538fd1498Szrj      the decls that matter.  */
37638fd1498Szrj   vec<tree, va_gc> *decls_in_scope;
37738fd1498Szrj   /* A list of goto statements to this label.  This is only used for
37838fd1498Szrj      goto statements seen before the label was defined, so that we can
37938fd1498Szrj      issue appropriate warnings for them.  */
38038fd1498Szrj   vec<c_goto_bindings_p, va_gc> *gotos;
38138fd1498Szrj };
38238fd1498Szrj 
38338fd1498Szrj /* Each c_scope structure describes the complete contents of one
38438fd1498Szrj    scope.  Four scopes are distinguished specially: the innermost or
38538fd1498Szrj    current scope, the innermost function scope, the file scope (always
38638fd1498Szrj    the second to outermost) and the outermost or external scope.
38738fd1498Szrj 
38838fd1498Szrj    Most declarations are recorded in the current scope.
38938fd1498Szrj 
39038fd1498Szrj    All normal label declarations are recorded in the innermost
39138fd1498Szrj    function scope, as are bindings of undeclared identifiers to
39238fd1498Szrj    error_mark_node.  (GCC permits nested functions as an extension,
39338fd1498Szrj    hence the 'innermost' qualifier.)  Explicitly declared labels
39438fd1498Szrj    (using the __label__ extension) appear in the current scope.
39538fd1498Szrj 
39638fd1498Szrj    Being in the file scope (current_scope == file_scope) causes
39738fd1498Szrj    special behavior in several places below.  Also, under some
39838fd1498Szrj    conditions the Objective-C front end records declarations in the
39938fd1498Szrj    file scope even though that isn't the current scope.
40038fd1498Szrj 
40138fd1498Szrj    All declarations with external linkage are recorded in the external
40238fd1498Szrj    scope, even if they aren't visible there; this models the fact that
40338fd1498Szrj    such declarations are visible to the entire program, and (with a
40438fd1498Szrj    bit of cleverness, see pushdecl) allows diagnosis of some violations
40538fd1498Szrj    of C99 6.2.2p7 and 6.2.7p2:
40638fd1498Szrj 
40738fd1498Szrj      If, within the same translation unit, the same identifier appears
40838fd1498Szrj      with both internal and external linkage, the behavior is
40938fd1498Szrj      undefined.
41038fd1498Szrj 
41138fd1498Szrj      All declarations that refer to the same object or function shall
41238fd1498Szrj      have compatible type; otherwise, the behavior is undefined.
41338fd1498Szrj 
41438fd1498Szrj    Initially only the built-in declarations, which describe compiler
41538fd1498Szrj    intrinsic functions plus a subset of the standard library, are in
41638fd1498Szrj    this scope.
41738fd1498Szrj 
41838fd1498Szrj    The order of the blocks list matters, and it is frequently appended
41938fd1498Szrj    to.  To avoid having to walk all the way to the end of the list on
42038fd1498Szrj    each insertion, or reverse the list later, we maintain a pointer to
42138fd1498Szrj    the last list entry.  (FIXME: It should be feasible to use a reversed
42238fd1498Szrj    list here.)
42338fd1498Szrj 
42438fd1498Szrj    The bindings list is strictly in reverse order of declarations;
42538fd1498Szrj    pop_scope relies on this.  */
42638fd1498Szrj 
42738fd1498Szrj 
42838fd1498Szrj struct GTY((chain_next ("%h.outer"))) c_scope {
42938fd1498Szrj   /* The scope containing this one.  */
43038fd1498Szrj   struct c_scope *outer;
43138fd1498Szrj 
43238fd1498Szrj   /* The next outermost function scope.  */
43338fd1498Szrj   struct c_scope *outer_function;
43438fd1498Szrj 
43538fd1498Szrj   /* All bindings in this scope.  */
43638fd1498Szrj   struct c_binding *bindings;
43738fd1498Szrj 
43838fd1498Szrj   /* For each scope (except the global one), a chain of BLOCK nodes
43938fd1498Szrj      for all the scopes that were entered and exited one level down.  */
44038fd1498Szrj   tree blocks;
44138fd1498Szrj   tree blocks_last;
44238fd1498Szrj 
44338fd1498Szrj   /* The depth of this scope.  Used to keep the ->shadowed chain of
44438fd1498Szrj      bindings sorted innermost to outermost.  */
44538fd1498Szrj   unsigned int depth : 28;
44638fd1498Szrj 
44738fd1498Szrj   /* True if we are currently filling this scope with parameter
44838fd1498Szrj      declarations.  */
44938fd1498Szrj   BOOL_BITFIELD parm_flag : 1;
45038fd1498Szrj 
45138fd1498Szrj   /* True if we saw [*] in this scope.  Used to give an error messages
45238fd1498Szrj      if these appears in a function definition.  */
45338fd1498Szrj   BOOL_BITFIELD had_vla_unspec : 1;
45438fd1498Szrj 
45538fd1498Szrj   /* True if we already complained about forward parameter decls
45638fd1498Szrj      in this scope.  This prevents double warnings on
45738fd1498Szrj      foo (int a; int b; ...)  */
45838fd1498Szrj   BOOL_BITFIELD warned_forward_parm_decls : 1;
45938fd1498Szrj 
46038fd1498Szrj   /* True if this is the outermost block scope of a function body.
46138fd1498Szrj      This scope contains the parameters, the local variables declared
46238fd1498Szrj      in the outermost block, and all the labels (except those in
46338fd1498Szrj      nested functions, or declared at block scope with __label__).  */
46438fd1498Szrj   BOOL_BITFIELD function_body : 1;
46538fd1498Szrj 
46638fd1498Szrj   /* True means make a BLOCK for this scope no matter what.  */
46738fd1498Szrj   BOOL_BITFIELD keep : 1;
46838fd1498Szrj 
46938fd1498Szrj   /* True means that an unsuffixed float constant is _Decimal64.  */
47038fd1498Szrj   BOOL_BITFIELD float_const_decimal64 : 1;
47138fd1498Szrj 
47238fd1498Szrj   /* True if this scope has any label bindings.  This is used to speed
47338fd1498Szrj      up searching for labels when popping scopes, particularly since
47438fd1498Szrj      labels are normally only found at function scope.  */
47538fd1498Szrj   BOOL_BITFIELD has_label_bindings : 1;
47638fd1498Szrj 
47738fd1498Szrj   /* True if we should issue a warning if a goto statement crosses any
47838fd1498Szrj      of the bindings.  We still need to check the list of bindings to
47938fd1498Szrj      find the specific ones we need to warn about.  This is true if
48038fd1498Szrj      decl_jump_unsafe would return true for any of the bindings.  This
48138fd1498Szrj      is used to avoid looping over all the bindings unnecessarily.  */
48238fd1498Szrj   BOOL_BITFIELD has_jump_unsafe_decl : 1;
48338fd1498Szrj };
48438fd1498Szrj 
48538fd1498Szrj /* The scope currently in effect.  */
48638fd1498Szrj 
48738fd1498Szrj static GTY(()) struct c_scope *current_scope;
48838fd1498Szrj 
48938fd1498Szrj /* The innermost function scope.  Ordinary (not explicitly declared)
49038fd1498Szrj    labels, bindings to error_mark_node, and the lazily-created
49138fd1498Szrj    bindings of __func__ and its friends get this scope.  */
49238fd1498Szrj 
49338fd1498Szrj static GTY(()) struct c_scope *current_function_scope;
49438fd1498Szrj 
49538fd1498Szrj /* The C file scope.  This is reset for each input translation unit.  */
49638fd1498Szrj 
49738fd1498Szrj static GTY(()) struct c_scope *file_scope;
49838fd1498Szrj 
49938fd1498Szrj /* The outermost scope.  This is used for all declarations with
50038fd1498Szrj    external linkage, and only these, hence the name.  */
50138fd1498Szrj 
50238fd1498Szrj static GTY(()) struct c_scope *external_scope;
50338fd1498Szrj 
50438fd1498Szrj /* A chain of c_scope structures awaiting reuse.  */
50538fd1498Szrj 
50638fd1498Szrj static GTY((deletable)) struct c_scope *scope_freelist;
50738fd1498Szrj 
50838fd1498Szrj /* A chain of c_binding structures awaiting reuse.  */
50938fd1498Szrj 
51038fd1498Szrj static GTY((deletable)) struct c_binding *binding_freelist;
51138fd1498Szrj 
51238fd1498Szrj /* Append VAR to LIST in scope SCOPE.  */
51338fd1498Szrj #define SCOPE_LIST_APPEND(scope, list, decl) do {	\
51438fd1498Szrj   struct c_scope *s_ = (scope);				\
51538fd1498Szrj   tree d_ = (decl);					\
51638fd1498Szrj   if (s_->list##_last)					\
51738fd1498Szrj     BLOCK_CHAIN (s_->list##_last) = d_;			\
51838fd1498Szrj   else							\
51938fd1498Szrj     s_->list = d_;					\
52038fd1498Szrj   s_->list##_last = d_;					\
52138fd1498Szrj } while (0)
52238fd1498Szrj 
52338fd1498Szrj /* Concatenate FROM in scope FSCOPE onto TO in scope TSCOPE.  */
52438fd1498Szrj #define SCOPE_LIST_CONCAT(tscope, to, fscope, from) do {	\
52538fd1498Szrj   struct c_scope *t_ = (tscope);				\
52638fd1498Szrj   struct c_scope *f_ = (fscope);				\
52738fd1498Szrj   if (t_->to##_last)						\
52838fd1498Szrj     BLOCK_CHAIN (t_->to##_last) = f_->from;			\
52938fd1498Szrj   else								\
53038fd1498Szrj     t_->to = f_->from;						\
53138fd1498Szrj   t_->to##_last = f_->from##_last;				\
53238fd1498Szrj } while (0)
53338fd1498Szrj 
53438fd1498Szrj /* A c_inline_static structure stores details of a static identifier
53538fd1498Szrj    referenced in a definition of a function that may be an inline
53638fd1498Szrj    definition if no subsequent declaration of that function uses
53738fd1498Szrj    "extern" or does not use "inline".  */
53838fd1498Szrj 
53938fd1498Szrj struct GTY((chain_next ("%h.next"))) c_inline_static {
54038fd1498Szrj   /* The location for a diagnostic.  */
54138fd1498Szrj   location_t location;
54238fd1498Szrj 
54338fd1498Szrj   /* The function that may be an inline definition.  */
54438fd1498Szrj   tree function;
54538fd1498Szrj 
54638fd1498Szrj   /* The object or function referenced.  */
54738fd1498Szrj   tree static_decl;
54838fd1498Szrj 
54938fd1498Szrj   /* What sort of reference this is.  */
55038fd1498Szrj   enum c_inline_static_type type;
55138fd1498Szrj 
55238fd1498Szrj   /* The next such structure or NULL.  */
55338fd1498Szrj   struct c_inline_static *next;
55438fd1498Szrj };
55538fd1498Szrj 
55638fd1498Szrj /* List of static identifiers used or referenced in functions that may
55738fd1498Szrj    be inline definitions.  */
55838fd1498Szrj static GTY(()) struct c_inline_static *c_inline_statics;
55938fd1498Szrj 
56038fd1498Szrj /* True means unconditionally make a BLOCK for the next scope pushed.  */
56138fd1498Szrj 
56238fd1498Szrj static bool keep_next_level_flag;
56338fd1498Szrj 
56438fd1498Szrj /* True means the next call to push_scope will be the outermost scope
56538fd1498Szrj    of a function body, so do not push a new scope, merely cease
56638fd1498Szrj    expecting parameter decls.  */
56738fd1498Szrj 
56838fd1498Szrj static bool next_is_function_body;
56938fd1498Szrj 
57038fd1498Szrj /* A vector of pointers to c_binding structures.  */
57138fd1498Szrj 
57238fd1498Szrj typedef struct c_binding *c_binding_ptr;
57338fd1498Szrj 
57438fd1498Szrj /* Information that we keep for a struct or union while it is being
57538fd1498Szrj    parsed.  */
57638fd1498Szrj 
57738fd1498Szrj struct c_struct_parse_info
57838fd1498Szrj {
57938fd1498Szrj   /* If warn_cxx_compat, a list of types defined within this
58038fd1498Szrj      struct.  */
58138fd1498Szrj   auto_vec<tree> struct_types;
58238fd1498Szrj   /* If warn_cxx_compat, a list of field names which have bindings,
58338fd1498Szrj      and which are defined in this struct, but which are not defined
58438fd1498Szrj      in any enclosing struct.  This is used to clear the in_struct
58538fd1498Szrj      field of the c_bindings structure.  */
58638fd1498Szrj   auto_vec<c_binding_ptr> fields;
58738fd1498Szrj   /* If warn_cxx_compat, a list of typedef names used when defining
58838fd1498Szrj      fields in this struct.  */
58938fd1498Szrj   auto_vec<tree> typedefs_seen;
59038fd1498Szrj };
59138fd1498Szrj 
59238fd1498Szrj /* Information for the struct or union currently being parsed, or
59338fd1498Szrj    NULL if not parsing a struct or union.  */
59438fd1498Szrj static struct c_struct_parse_info *struct_parse_info;
59538fd1498Szrj 
59638fd1498Szrj /* Forward declarations.  */
59738fd1498Szrj static tree lookup_name_in_scope (tree, struct c_scope *);
59838fd1498Szrj static tree c_make_fname_decl (location_t, tree, int);
59938fd1498Szrj static tree grokdeclarator (const struct c_declarator *,
60038fd1498Szrj 			    struct c_declspecs *,
60138fd1498Szrj 			    enum decl_context, bool, tree *, tree *, tree *,
60238fd1498Szrj 			    bool *, enum deprecated_states);
60338fd1498Szrj static tree grokparms (struct c_arg_info *, bool);
60438fd1498Szrj static void layout_array_type (tree);
60538fd1498Szrj static void warn_defaults_to (location_t, int, const char *, ...)
60638fd1498Szrj     ATTRIBUTE_GCC_DIAG(3,4);
60738fd1498Szrj 
60838fd1498Szrj /* T is a statement.  Add it to the statement-tree.  This is the
60938fd1498Szrj    C/ObjC version--C++ has a slightly different version of this
61038fd1498Szrj    function.  */
61138fd1498Szrj 
61238fd1498Szrj tree
add_stmt(tree t)61338fd1498Szrj add_stmt (tree t)
61438fd1498Szrj {
61538fd1498Szrj   enum tree_code code = TREE_CODE (t);
61638fd1498Szrj 
61738fd1498Szrj   if (CAN_HAVE_LOCATION_P (t) && code != LABEL_EXPR)
61838fd1498Szrj     {
61938fd1498Szrj       if (!EXPR_HAS_LOCATION (t))
62038fd1498Szrj 	SET_EXPR_LOCATION (t, input_location);
62138fd1498Szrj     }
62238fd1498Szrj 
62338fd1498Szrj   if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
62438fd1498Szrj     STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1;
62538fd1498Szrj 
62638fd1498Szrj   /* Add T to the statement-tree.  Non-side-effect statements need to be
62738fd1498Szrj      recorded during statement expressions.  */
62838fd1498Szrj   if (!building_stmt_list_p ())
62938fd1498Szrj     push_stmt_list ();
63038fd1498Szrj   append_to_statement_list_force (t, &cur_stmt_list);
63138fd1498Szrj 
63238fd1498Szrj   return t;
63338fd1498Szrj }
63438fd1498Szrj 
63538fd1498Szrj /* Build a pointer type using the default pointer mode.  */
63638fd1498Szrj 
63738fd1498Szrj static tree
c_build_pointer_type(tree to_type)63838fd1498Szrj c_build_pointer_type (tree to_type)
63938fd1498Szrj {
64038fd1498Szrj   addr_space_t as = to_type == error_mark_node? ADDR_SPACE_GENERIC
64138fd1498Szrj 					      : TYPE_ADDR_SPACE (to_type);
64238fd1498Szrj   machine_mode pointer_mode;
64338fd1498Szrj 
64438fd1498Szrj   if (as != ADDR_SPACE_GENERIC || c_default_pointer_mode == VOIDmode)
64538fd1498Szrj     pointer_mode = targetm.addr_space.pointer_mode (as);
64638fd1498Szrj   else
64738fd1498Szrj     pointer_mode = c_default_pointer_mode;
64838fd1498Szrj   return build_pointer_type_for_mode (to_type, pointer_mode, false);
64938fd1498Szrj }
65038fd1498Szrj 
65138fd1498Szrj 
65238fd1498Szrj /* Return true if we will want to say something if a goto statement
65338fd1498Szrj    crosses DECL.  */
65438fd1498Szrj 
65538fd1498Szrj static bool
decl_jump_unsafe(tree decl)65638fd1498Szrj decl_jump_unsafe (tree decl)
65738fd1498Szrj {
65838fd1498Szrj   if (error_operand_p (decl))
65938fd1498Szrj     return false;
66038fd1498Szrj 
66138fd1498Szrj   /* Always warn about crossing variably modified types.  */
66238fd1498Szrj   if ((VAR_P (decl) || TREE_CODE (decl) == TYPE_DECL)
66338fd1498Szrj       && variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
66438fd1498Szrj     return true;
66538fd1498Szrj 
66638fd1498Szrj   /* Otherwise, only warn if -Wgoto-misses-init and this is an
66738fd1498Szrj      initialized automatic decl.  */
66838fd1498Szrj   if (warn_jump_misses_init
66938fd1498Szrj       && VAR_P (decl)
67038fd1498Szrj       && !TREE_STATIC (decl)
67138fd1498Szrj       && DECL_INITIAL (decl) != NULL_TREE)
67238fd1498Szrj     return true;
67338fd1498Szrj 
67438fd1498Szrj   return false;
67538fd1498Szrj }
67638fd1498Szrj 
67738fd1498Szrj 
67838fd1498Szrj void
c_print_identifier(FILE * file,tree node,int indent)67938fd1498Szrj c_print_identifier (FILE *file, tree node, int indent)
68038fd1498Szrj {
68138fd1498Szrj   void (*save) (enum c_oracle_request, tree identifier);
68238fd1498Szrj 
68338fd1498Szrj   /* Temporarily hide any binding oracle.  Without this, calls to
68438fd1498Szrj      debug_tree from the debugger will end up calling into the oracle,
68538fd1498Szrj      making for a confusing debug session.  As the oracle isn't needed
68638fd1498Szrj      here for normal operation, it's simplest to suppress it.  */
68738fd1498Szrj   save = c_binding_oracle;
68838fd1498Szrj   c_binding_oracle = NULL;
68938fd1498Szrj 
69038fd1498Szrj   print_node (file, "symbol", I_SYMBOL_DECL (node), indent + 4);
69138fd1498Szrj   print_node (file, "tag", I_TAG_DECL (node), indent + 4);
69238fd1498Szrj   print_node (file, "label", I_LABEL_DECL (node), indent + 4);
69338fd1498Szrj   if (C_IS_RESERVED_WORD (node) && C_RID_CODE (node) != RID_CXX_COMPAT_WARN)
69438fd1498Szrj     {
69538fd1498Szrj       tree rid = ridpointers[C_RID_CODE (node)];
69638fd1498Szrj       indent_to (file, indent + 4);
69738fd1498Szrj       fprintf (file, "rid " HOST_PTR_PRINTF " \"%s\"",
69838fd1498Szrj 	       (void *) rid, IDENTIFIER_POINTER (rid));
69938fd1498Szrj     }
70038fd1498Szrj 
70138fd1498Szrj   c_binding_oracle = save;
70238fd1498Szrj }
70338fd1498Szrj 
70438fd1498Szrj /* Establish a binding between NAME, an IDENTIFIER_NODE, and DECL,
70538fd1498Szrj    which may be any of several kinds of DECL or TYPE or error_mark_node,
70638fd1498Szrj    in the scope SCOPE.  */
70738fd1498Szrj static void
bind(tree name,tree decl,struct c_scope * scope,bool invisible,bool nested,location_t locus)70838fd1498Szrj bind (tree name, tree decl, struct c_scope *scope, bool invisible,
70938fd1498Szrj       bool nested, location_t locus)
71038fd1498Szrj {
71138fd1498Szrj   struct c_binding *b, **here;
71238fd1498Szrj 
71338fd1498Szrj   if (binding_freelist)
71438fd1498Szrj     {
71538fd1498Szrj       b = binding_freelist;
71638fd1498Szrj       binding_freelist = b->prev;
71738fd1498Szrj     }
71838fd1498Szrj   else
71938fd1498Szrj     b = ggc_alloc<c_binding> ();
72038fd1498Szrj 
72138fd1498Szrj   b->shadowed = 0;
72238fd1498Szrj   b->decl = decl;
72338fd1498Szrj   b->id = name;
72438fd1498Szrj   b->depth = scope->depth;
72538fd1498Szrj   b->invisible = invisible;
72638fd1498Szrj   b->nested = nested;
72738fd1498Szrj   b->inner_comp = 0;
72838fd1498Szrj   b->in_struct = 0;
72938fd1498Szrj   b->locus = locus;
73038fd1498Szrj 
73138fd1498Szrj   b->u.type = NULL;
73238fd1498Szrj 
73338fd1498Szrj   b->prev = scope->bindings;
73438fd1498Szrj   scope->bindings = b;
73538fd1498Szrj 
73638fd1498Szrj   if (decl_jump_unsafe (decl))
73738fd1498Szrj     scope->has_jump_unsafe_decl = 1;
73838fd1498Szrj 
73938fd1498Szrj   if (!name)
74038fd1498Szrj     return;
74138fd1498Szrj 
74238fd1498Szrj   switch (TREE_CODE (decl))
74338fd1498Szrj     {
74438fd1498Szrj     case LABEL_DECL:     here = &I_LABEL_BINDING (name);   break;
74538fd1498Szrj     case ENUMERAL_TYPE:
74638fd1498Szrj     case UNION_TYPE:
74738fd1498Szrj     case RECORD_TYPE:    here = &I_TAG_BINDING (name);     break;
74838fd1498Szrj     case VAR_DECL:
74938fd1498Szrj     case FUNCTION_DECL:
75038fd1498Szrj     case TYPE_DECL:
75138fd1498Szrj     case CONST_DECL:
75238fd1498Szrj     case PARM_DECL:
75338fd1498Szrj     case ERROR_MARK:     here = &I_SYMBOL_BINDING (name);  break;
75438fd1498Szrj 
75538fd1498Szrj     default:
75638fd1498Szrj       gcc_unreachable ();
75738fd1498Szrj     }
75838fd1498Szrj 
75938fd1498Szrj   /* Locate the appropriate place in the chain of shadowed decls
76038fd1498Szrj      to insert this binding.  Normally, scope == current_scope and
76138fd1498Szrj      this does nothing.  */
76238fd1498Szrj   while (*here && (*here)->depth > scope->depth)
76338fd1498Szrj     here = &(*here)->shadowed;
76438fd1498Szrj 
76538fd1498Szrj   b->shadowed = *here;
76638fd1498Szrj   *here = b;
76738fd1498Szrj }
76838fd1498Szrj 
76938fd1498Szrj /* Clear the binding structure B, stick it on the binding_freelist,
77038fd1498Szrj    and return the former value of b->prev.  This is used by pop_scope
77138fd1498Szrj    and get_parm_info to iterate destructively over all the bindings
77238fd1498Szrj    from a given scope.  */
77338fd1498Szrj static struct c_binding *
free_binding_and_advance(struct c_binding * b)77438fd1498Szrj free_binding_and_advance (struct c_binding *b)
77538fd1498Szrj {
77638fd1498Szrj   struct c_binding *prev = b->prev;
77738fd1498Szrj 
77838fd1498Szrj   memset (b, 0, sizeof (struct c_binding));
77938fd1498Szrj   b->prev = binding_freelist;
78038fd1498Szrj   binding_freelist = b;
78138fd1498Szrj 
78238fd1498Szrj   return prev;
78338fd1498Szrj }
78438fd1498Szrj 
78538fd1498Szrj /* Bind a label.  Like bind, but skip fields which aren't used for
78638fd1498Szrj    labels, and add the LABEL_VARS value.  */
78738fd1498Szrj static void
bind_label(tree name,tree label,struct c_scope * scope,struct c_label_vars * label_vars)78838fd1498Szrj bind_label (tree name, tree label, struct c_scope *scope,
78938fd1498Szrj 	    struct c_label_vars *label_vars)
79038fd1498Szrj {
79138fd1498Szrj   struct c_binding *b;
79238fd1498Szrj 
79338fd1498Szrj   bind (name, label, scope, /*invisible=*/false, /*nested=*/false,
79438fd1498Szrj 	UNKNOWN_LOCATION);
79538fd1498Szrj 
79638fd1498Szrj   scope->has_label_bindings = true;
79738fd1498Szrj 
79838fd1498Szrj   b = scope->bindings;
79938fd1498Szrj   gcc_assert (b->decl == label);
80038fd1498Szrj   label_vars->shadowed = b->u.label;
80138fd1498Szrj   b->u.label = label_vars;
80238fd1498Szrj }
80338fd1498Szrj 
80438fd1498Szrj /* Hook called at end of compilation to assume 1 elt
80538fd1498Szrj    for a file-scope tentative array defn that wasn't complete before.  */
80638fd1498Szrj 
80738fd1498Szrj void
c_finish_incomplete_decl(tree decl)80838fd1498Szrj c_finish_incomplete_decl (tree decl)
80938fd1498Szrj {
81038fd1498Szrj   if (VAR_P (decl))
81138fd1498Szrj     {
81238fd1498Szrj       tree type = TREE_TYPE (decl);
81338fd1498Szrj       if (type != error_mark_node
81438fd1498Szrj 	  && TREE_CODE (type) == ARRAY_TYPE
81538fd1498Szrj 	  && !DECL_EXTERNAL (decl)
81638fd1498Szrj 	  && TYPE_DOMAIN (type) == NULL_TREE)
81738fd1498Szrj 	{
81838fd1498Szrj 	  warning_at (DECL_SOURCE_LOCATION (decl),
81938fd1498Szrj 		      0, "array %q+D assumed to have one element", decl);
82038fd1498Szrj 
82138fd1498Szrj 	  complete_array_type (&TREE_TYPE (decl), NULL_TREE, true);
82238fd1498Szrj 
82338fd1498Szrj 	  relayout_decl (decl);
82438fd1498Szrj 	}
82538fd1498Szrj     }
82638fd1498Szrj }
82738fd1498Szrj 
82838fd1498Szrj /* Record that inline function FUNC contains a reference (location
82938fd1498Szrj    LOC) to static DECL (file-scope or function-local according to
83038fd1498Szrj    TYPE).  */
83138fd1498Szrj 
83238fd1498Szrj void
record_inline_static(location_t loc,tree func,tree decl,enum c_inline_static_type type)83338fd1498Szrj record_inline_static (location_t loc, tree func, tree decl,
83438fd1498Szrj 		      enum c_inline_static_type type)
83538fd1498Szrj {
83638fd1498Szrj   c_inline_static *csi = ggc_alloc<c_inline_static> ();
83738fd1498Szrj   csi->location = loc;
83838fd1498Szrj   csi->function = func;
83938fd1498Szrj   csi->static_decl = decl;
84038fd1498Szrj   csi->type = type;
84138fd1498Szrj   csi->next = c_inline_statics;
84238fd1498Szrj   c_inline_statics = csi;
84338fd1498Szrj }
84438fd1498Szrj 
84538fd1498Szrj /* Check for references to static declarations in inline functions at
84638fd1498Szrj    the end of the translation unit and diagnose them if the functions
84738fd1498Szrj    are still inline definitions.  */
84838fd1498Szrj 
84938fd1498Szrj static void
check_inline_statics(void)85038fd1498Szrj check_inline_statics (void)
85138fd1498Szrj {
85238fd1498Szrj   struct c_inline_static *csi;
85338fd1498Szrj   for (csi = c_inline_statics; csi; csi = csi->next)
85438fd1498Szrj     {
85538fd1498Szrj       if (DECL_EXTERNAL (csi->function))
85638fd1498Szrj 	switch (csi->type)
85738fd1498Szrj 	  {
85838fd1498Szrj 	  case csi_internal:
85938fd1498Szrj 	    pedwarn (csi->location, 0,
86038fd1498Szrj 		     "%qD is static but used in inline function %qD "
86138fd1498Szrj 		     "which is not static", csi->static_decl, csi->function);
86238fd1498Szrj 	    break;
86338fd1498Szrj 	  case csi_modifiable:
86438fd1498Szrj 	    pedwarn (csi->location, 0,
86538fd1498Szrj 		     "%q+D is static but declared in inline function %qD "
86638fd1498Szrj 		     "which is not static", csi->static_decl, csi->function);
86738fd1498Szrj 	    break;
86838fd1498Szrj 	  default:
86938fd1498Szrj 	    gcc_unreachable ();
87038fd1498Szrj 	  }
87138fd1498Szrj     }
87238fd1498Szrj   c_inline_statics = NULL;
87338fd1498Szrj }
87438fd1498Szrj 
87538fd1498Szrj /* Fill in a c_spot_bindings structure.  If DEFINING is true, set it
87638fd1498Szrj    for the current state, otherwise set it to uninitialized.  */
87738fd1498Szrj 
87838fd1498Szrj static void
set_spot_bindings(struct c_spot_bindings * p,bool defining)87938fd1498Szrj set_spot_bindings (struct c_spot_bindings *p, bool defining)
88038fd1498Szrj {
88138fd1498Szrj   if (defining)
88238fd1498Szrj     {
88338fd1498Szrj       p->scope = current_scope;
88438fd1498Szrj       p->bindings_in_scope = current_scope->bindings;
88538fd1498Szrj     }
88638fd1498Szrj   else
88738fd1498Szrj     {
88838fd1498Szrj       p->scope = NULL;
88938fd1498Szrj       p->bindings_in_scope = NULL;
89038fd1498Szrj     }
89138fd1498Szrj   p->stmt_exprs = 0;
89238fd1498Szrj   p->left_stmt_expr = false;
89338fd1498Szrj }
89438fd1498Szrj 
89538fd1498Szrj /* Update spot bindings P as we pop out of SCOPE.  Return true if we
89638fd1498Szrj    should push decls for a label.  */
89738fd1498Szrj 
89838fd1498Szrj static bool
update_spot_bindings(struct c_scope * scope,struct c_spot_bindings * p)89938fd1498Szrj update_spot_bindings (struct c_scope *scope, struct c_spot_bindings *p)
90038fd1498Szrj {
90138fd1498Szrj   if (p->scope != scope)
90238fd1498Szrj     {
90338fd1498Szrj       /* This label or goto is defined in some other scope, or it is a
90438fd1498Szrj 	 label which is not yet defined.  There is nothing to
90538fd1498Szrj 	 update.  */
90638fd1498Szrj       return false;
90738fd1498Szrj     }
90838fd1498Szrj 
90938fd1498Szrj   /* Adjust the spot bindings to refer to the bindings already defined
91038fd1498Szrj      in the enclosing scope.  */
91138fd1498Szrj   p->scope = scope->outer;
91238fd1498Szrj   p->bindings_in_scope = p->scope->bindings;
91338fd1498Szrj 
91438fd1498Szrj   return true;
91538fd1498Szrj }
91638fd1498Szrj 
91738fd1498Szrj /* The Objective-C front-end often needs to determine the current scope.  */
91838fd1498Szrj 
91938fd1498Szrj void *
objc_get_current_scope(void)92038fd1498Szrj objc_get_current_scope (void)
92138fd1498Szrj {
92238fd1498Szrj   return current_scope;
92338fd1498Szrj }
92438fd1498Szrj 
92538fd1498Szrj /* The following function is used only by Objective-C.  It needs to live here
92638fd1498Szrj    because it accesses the innards of c_scope.  */
92738fd1498Szrj 
92838fd1498Szrj void
objc_mark_locals_volatile(void * enclosing_blk)92938fd1498Szrj objc_mark_locals_volatile (void *enclosing_blk)
93038fd1498Szrj {
93138fd1498Szrj   struct c_scope *scope;
93238fd1498Szrj   struct c_binding *b;
93338fd1498Szrj 
93438fd1498Szrj   for (scope = current_scope;
93538fd1498Szrj        scope && scope != enclosing_blk;
93638fd1498Szrj        scope = scope->outer)
93738fd1498Szrj     {
93838fd1498Szrj       for (b = scope->bindings; b; b = b->prev)
93938fd1498Szrj 	objc_volatilize_decl (b->decl);
94038fd1498Szrj 
94138fd1498Szrj       /* Do not climb up past the current function.  */
94238fd1498Szrj       if (scope->function_body)
94338fd1498Szrj 	break;
94438fd1498Szrj     }
94538fd1498Szrj }
94638fd1498Szrj 
94738fd1498Szrj /* Return true if we are in the global binding level.  */
94838fd1498Szrj 
94938fd1498Szrj bool
global_bindings_p(void)95038fd1498Szrj global_bindings_p (void)
95138fd1498Szrj {
95238fd1498Szrj   return current_scope == file_scope;
95338fd1498Szrj }
95438fd1498Szrj 
95538fd1498Szrj void
keep_next_level(void)95638fd1498Szrj keep_next_level (void)
95738fd1498Szrj {
95838fd1498Szrj   keep_next_level_flag = true;
95938fd1498Szrj }
96038fd1498Szrj 
96138fd1498Szrj /* Set the flag for the FLOAT_CONST_DECIMAL64 pragma being ON.  */
96238fd1498Szrj 
96338fd1498Szrj void
set_float_const_decimal64(void)96438fd1498Szrj set_float_const_decimal64 (void)
96538fd1498Szrj {
96638fd1498Szrj   current_scope->float_const_decimal64 = true;
96738fd1498Szrj }
96838fd1498Szrj 
96938fd1498Szrj /* Clear the flag for the FLOAT_CONST_DECIMAL64 pragma.  */
97038fd1498Szrj 
97138fd1498Szrj void
clear_float_const_decimal64(void)97238fd1498Szrj clear_float_const_decimal64 (void)
97338fd1498Szrj {
97438fd1498Szrj   current_scope->float_const_decimal64 = false;
97538fd1498Szrj }
97638fd1498Szrj 
97738fd1498Szrj /* Return nonzero if an unsuffixed float constant is _Decimal64.  */
97838fd1498Szrj 
97938fd1498Szrj bool
float_const_decimal64_p(void)98038fd1498Szrj float_const_decimal64_p (void)
98138fd1498Szrj {
98238fd1498Szrj   return current_scope->float_const_decimal64;
98338fd1498Szrj }
98438fd1498Szrj 
98538fd1498Szrj /* Identify this scope as currently being filled with parameters.  */
98638fd1498Szrj 
98738fd1498Szrj void
declare_parm_level(void)98838fd1498Szrj declare_parm_level (void)
98938fd1498Szrj {
99038fd1498Szrj   current_scope->parm_flag = true;
99138fd1498Szrj }
99238fd1498Szrj 
99338fd1498Szrj void
push_scope(void)99438fd1498Szrj push_scope (void)
99538fd1498Szrj {
99638fd1498Szrj   if (next_is_function_body)
99738fd1498Szrj     {
99838fd1498Szrj       /* This is the transition from the parameters to the top level
99938fd1498Szrj 	 of the function body.  These are the same scope
100038fd1498Szrj 	 (C99 6.2.1p4,6) so we do not push another scope structure.
100138fd1498Szrj 	 next_is_function_body is set only by store_parm_decls, which
100238fd1498Szrj 	 in turn is called when and only when we are about to
100338fd1498Szrj 	 encounter the opening curly brace for the function body.
100438fd1498Szrj 
100538fd1498Szrj 	 The outermost block of a function always gets a BLOCK node,
100638fd1498Szrj 	 because the debugging output routines expect that each
100738fd1498Szrj 	 function has at least one BLOCK.  */
100838fd1498Szrj       current_scope->parm_flag         = false;
100938fd1498Szrj       current_scope->function_body     = true;
101038fd1498Szrj       current_scope->keep              = true;
101138fd1498Szrj       current_scope->outer_function    = current_function_scope;
101238fd1498Szrj       current_function_scope           = current_scope;
101338fd1498Szrj 
101438fd1498Szrj       keep_next_level_flag = false;
101538fd1498Szrj       next_is_function_body = false;
101638fd1498Szrj 
101738fd1498Szrj       /* The FLOAT_CONST_DECIMAL64 pragma applies to nested scopes.  */
101838fd1498Szrj       if (current_scope->outer)
101938fd1498Szrj 	current_scope->float_const_decimal64
102038fd1498Szrj 	  = current_scope->outer->float_const_decimal64;
102138fd1498Szrj       else
102238fd1498Szrj 	current_scope->float_const_decimal64 = false;
102338fd1498Szrj     }
102438fd1498Szrj   else
102538fd1498Szrj     {
102638fd1498Szrj       struct c_scope *scope;
102738fd1498Szrj       if (scope_freelist)
102838fd1498Szrj 	{
102938fd1498Szrj 	  scope = scope_freelist;
103038fd1498Szrj 	  scope_freelist = scope->outer;
103138fd1498Szrj 	}
103238fd1498Szrj       else
103338fd1498Szrj 	scope = ggc_cleared_alloc<c_scope> ();
103438fd1498Szrj 
103538fd1498Szrj       /* The FLOAT_CONST_DECIMAL64 pragma applies to nested scopes.  */
103638fd1498Szrj       if (current_scope)
103738fd1498Szrj 	scope->float_const_decimal64 = current_scope->float_const_decimal64;
103838fd1498Szrj       else
103938fd1498Szrj 	scope->float_const_decimal64 = false;
104038fd1498Szrj 
104138fd1498Szrj       scope->keep          = keep_next_level_flag;
104238fd1498Szrj       scope->outer         = current_scope;
104338fd1498Szrj       scope->depth	   = current_scope ? (current_scope->depth + 1) : 0;
104438fd1498Szrj 
104538fd1498Szrj       /* Check for scope depth overflow.  Unlikely (2^28 == 268,435,456) but
104638fd1498Szrj 	 possible.  */
104738fd1498Szrj       if (current_scope && scope->depth == 0)
104838fd1498Szrj 	{
104938fd1498Szrj 	  scope->depth--;
105038fd1498Szrj 	  sorry ("GCC supports only %u nested scopes", scope->depth);
105138fd1498Szrj 	}
105238fd1498Szrj 
105338fd1498Szrj       current_scope        = scope;
105438fd1498Szrj       keep_next_level_flag = false;
105538fd1498Szrj     }
105638fd1498Szrj }
105738fd1498Szrj 
105838fd1498Szrj /* This is called when we are leaving SCOPE.  For each label defined
105938fd1498Szrj    in SCOPE, add any appropriate decls to its decls_in_scope fields.
106038fd1498Szrj    These are the decls whose initialization will be skipped by a goto
106138fd1498Szrj    later in the function.  */
106238fd1498Szrj 
106338fd1498Szrj static void
update_label_decls(struct c_scope * scope)106438fd1498Szrj update_label_decls (struct c_scope *scope)
106538fd1498Szrj {
106638fd1498Szrj   struct c_scope *s;
106738fd1498Szrj 
106838fd1498Szrj   s = scope;
106938fd1498Szrj   while (s != NULL)
107038fd1498Szrj     {
107138fd1498Szrj       if (s->has_label_bindings)
107238fd1498Szrj 	{
107338fd1498Szrj 	  struct c_binding *b;
107438fd1498Szrj 
107538fd1498Szrj 	  for (b = s->bindings; b != NULL; b = b->prev)
107638fd1498Szrj 	    {
107738fd1498Szrj 	      struct c_label_vars *label_vars;
107838fd1498Szrj 	      struct c_binding *b1;
107938fd1498Szrj 	      bool hjud;
108038fd1498Szrj 	      unsigned int ix;
108138fd1498Szrj 	      struct c_goto_bindings *g;
108238fd1498Szrj 
108338fd1498Szrj 	      if (TREE_CODE (b->decl) != LABEL_DECL)
108438fd1498Szrj 		continue;
108538fd1498Szrj 	      label_vars = b->u.label;
108638fd1498Szrj 
108738fd1498Szrj 	      b1 = label_vars->label_bindings.bindings_in_scope;
108838fd1498Szrj 	      if (label_vars->label_bindings.scope == NULL)
108938fd1498Szrj 		hjud = false;
109038fd1498Szrj 	      else
109138fd1498Szrj 		hjud = label_vars->label_bindings.scope->has_jump_unsafe_decl;
109238fd1498Szrj 	      if (update_spot_bindings (scope, &label_vars->label_bindings))
109338fd1498Szrj 		{
109438fd1498Szrj 		  /* This label is defined in this scope.  */
109538fd1498Szrj 		  if (hjud)
109638fd1498Szrj 		    {
109738fd1498Szrj 		      for (; b1 != NULL; b1 = b1->prev)
109838fd1498Szrj 			{
109938fd1498Szrj 			  /* A goto from later in the function to this
110038fd1498Szrj 			     label will never see the initialization
110138fd1498Szrj 			     of B1, if any.  Save it to issue a
110238fd1498Szrj 			     warning if needed.  */
110338fd1498Szrj 			  if (decl_jump_unsafe (b1->decl))
110438fd1498Szrj 			    vec_safe_push(label_vars->decls_in_scope, b1->decl);
110538fd1498Szrj 			}
110638fd1498Szrj 		    }
110738fd1498Szrj 		}
110838fd1498Szrj 
110938fd1498Szrj 	      /* Update the bindings of any goto statements associated
111038fd1498Szrj 		 with this label.  */
111138fd1498Szrj 	      FOR_EACH_VEC_SAFE_ELT (label_vars->gotos, ix, g)
111238fd1498Szrj 		update_spot_bindings (scope, &g->goto_bindings);
111338fd1498Szrj 	    }
111438fd1498Szrj 	}
111538fd1498Szrj 
111638fd1498Szrj       /* Don't search beyond the current function.  */
111738fd1498Szrj       if (s == current_function_scope)
111838fd1498Szrj 	break;
111938fd1498Szrj 
112038fd1498Szrj       s = s->outer;
112138fd1498Szrj     }
112238fd1498Szrj }
112338fd1498Szrj 
112438fd1498Szrj /* Set the TYPE_CONTEXT of all of TYPE's variants to CONTEXT.  */
112538fd1498Szrj 
112638fd1498Szrj static void
set_type_context(tree type,tree context)112738fd1498Szrj set_type_context (tree type, tree context)
112838fd1498Szrj {
112938fd1498Szrj   for (type = TYPE_MAIN_VARIANT (type); type;
113038fd1498Szrj        type = TYPE_NEXT_VARIANT (type))
113138fd1498Szrj     TYPE_CONTEXT (type) = context;
113238fd1498Szrj }
113338fd1498Szrj 
113438fd1498Szrj /* Exit a scope.  Restore the state of the identifier-decl mappings
113538fd1498Szrj    that were in effect when this scope was entered.  Return a BLOCK
113638fd1498Szrj    node containing all the DECLs in this scope that are of interest
113738fd1498Szrj    to debug info generation.  */
113838fd1498Szrj 
113938fd1498Szrj tree
pop_scope(void)114038fd1498Szrj pop_scope (void)
114138fd1498Szrj {
114238fd1498Szrj   struct c_scope *scope = current_scope;
114338fd1498Szrj   tree block, context, p;
114438fd1498Szrj   struct c_binding *b;
114538fd1498Szrj 
114638fd1498Szrj   bool functionbody = scope->function_body;
114738fd1498Szrj   bool keep = functionbody || scope->keep || scope->bindings;
114838fd1498Szrj 
114938fd1498Szrj   update_label_decls (scope);
115038fd1498Szrj 
115138fd1498Szrj   /* If appropriate, create a BLOCK to record the decls for the life
115238fd1498Szrj      of this function.  */
115338fd1498Szrj   block = NULL_TREE;
115438fd1498Szrj   if (keep)
115538fd1498Szrj     {
115638fd1498Szrj       block = make_node (BLOCK);
115738fd1498Szrj       BLOCK_SUBBLOCKS (block) = scope->blocks;
115838fd1498Szrj       TREE_USED (block) = 1;
115938fd1498Szrj 
116038fd1498Szrj       /* In each subblock, record that this is its superior.  */
116138fd1498Szrj       for (p = scope->blocks; p; p = BLOCK_CHAIN (p))
116238fd1498Szrj 	BLOCK_SUPERCONTEXT (p) = block;
116338fd1498Szrj 
116438fd1498Szrj       BLOCK_VARS (block) = NULL_TREE;
116538fd1498Szrj     }
116638fd1498Szrj 
116738fd1498Szrj   /* The TYPE_CONTEXTs for all of the tagged types belonging to this
116838fd1498Szrj      scope must be set so that they point to the appropriate
116938fd1498Szrj      construct, i.e.  either to the current FUNCTION_DECL node, or
117038fd1498Szrj      else to the BLOCK node we just constructed.
117138fd1498Szrj 
117238fd1498Szrj      Note that for tagged types whose scope is just the formal
117338fd1498Szrj      parameter list for some function type specification, we can't
117438fd1498Szrj      properly set their TYPE_CONTEXTs here, because we don't have a
117538fd1498Szrj      pointer to the appropriate FUNCTION_TYPE node readily available
117638fd1498Szrj      to us.  For those cases, the TYPE_CONTEXTs of the relevant tagged
117738fd1498Szrj      type nodes get set in `grokdeclarator' as soon as we have created
117838fd1498Szrj      the FUNCTION_TYPE node which will represent the "scope" for these
117938fd1498Szrj      "parameter list local" tagged types.  */
118038fd1498Szrj   if (scope->function_body)
118138fd1498Szrj     context = current_function_decl;
118238fd1498Szrj   else if (scope == file_scope)
118338fd1498Szrj     {
118438fd1498Szrj       tree file_decl
118538fd1498Szrj 	= build_translation_unit_decl (get_identifier (main_input_filename));
118638fd1498Szrj       context = file_decl;
118738fd1498Szrj       debug_hooks->register_main_translation_unit (file_decl);
118838fd1498Szrj     }
118938fd1498Szrj   else
119038fd1498Szrj     context = block;
119138fd1498Szrj 
119238fd1498Szrj   /* Clear all bindings in this scope.  */
119338fd1498Szrj   for (b = scope->bindings; b; b = free_binding_and_advance (b))
119438fd1498Szrj     {
119538fd1498Szrj       p = b->decl;
119638fd1498Szrj       switch (TREE_CODE (p))
119738fd1498Szrj 	{
119838fd1498Szrj 	case LABEL_DECL:
119938fd1498Szrj 	  /* Warnings for unused labels, errors for undefined labels.  */
120038fd1498Szrj 	  if (TREE_USED (p) && !DECL_INITIAL (p))
120138fd1498Szrj 	    {
120238fd1498Szrj 	      error ("label %q+D used but not defined", p);
120338fd1498Szrj 	      DECL_INITIAL (p) = error_mark_node;
120438fd1498Szrj 	    }
120538fd1498Szrj 	  else
120638fd1498Szrj 	    warn_for_unused_label (p);
120738fd1498Szrj 
120838fd1498Szrj 	  /* Labels go in BLOCK_VARS.  */
120938fd1498Szrj 	  DECL_CHAIN (p) = BLOCK_VARS (block);
121038fd1498Szrj 	  BLOCK_VARS (block) = p;
121138fd1498Szrj 	  gcc_assert (I_LABEL_BINDING (b->id) == b);
121238fd1498Szrj 	  I_LABEL_BINDING (b->id) = b->shadowed;
121338fd1498Szrj 
121438fd1498Szrj 	  /* Also pop back to the shadowed label_vars.  */
121538fd1498Szrj 	  release_tree_vector (b->u.label->decls_in_scope);
121638fd1498Szrj 	  b->u.label = b->u.label->shadowed;
121738fd1498Szrj 	  break;
121838fd1498Szrj 
121938fd1498Szrj 	case ENUMERAL_TYPE:
122038fd1498Szrj 	case UNION_TYPE:
122138fd1498Szrj 	case RECORD_TYPE:
122238fd1498Szrj 	  set_type_context (p, context);
122338fd1498Szrj 
122438fd1498Szrj 	  /* Types may not have tag-names, in which case the type
122538fd1498Szrj 	     appears in the bindings list with b->id NULL.  */
122638fd1498Szrj 	  if (b->id)
122738fd1498Szrj 	    {
122838fd1498Szrj 	      gcc_assert (I_TAG_BINDING (b->id) == b);
122938fd1498Szrj 	      I_TAG_BINDING (b->id) = b->shadowed;
123038fd1498Szrj 	    }
123138fd1498Szrj 	  break;
123238fd1498Szrj 
123338fd1498Szrj 	case FUNCTION_DECL:
123438fd1498Szrj 	  /* Propagate TREE_ADDRESSABLE from nested functions to their
123538fd1498Szrj 	     containing functions.  */
123638fd1498Szrj 	  if (!TREE_ASM_WRITTEN (p)
123738fd1498Szrj 	      && DECL_INITIAL (p) != NULL_TREE
123838fd1498Szrj 	      && TREE_ADDRESSABLE (p)
123938fd1498Szrj 	      && DECL_ABSTRACT_ORIGIN (p) != NULL_TREE
124038fd1498Szrj 	      && DECL_ABSTRACT_ORIGIN (p) != p)
124138fd1498Szrj 	    TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (p)) = 1;
1242*58e805e6Szrj 	  if (!TREE_PUBLIC (p)
124338fd1498Szrj 	      && !DECL_INITIAL (p)
1244*58e805e6Szrj 	      && !b->nested
124538fd1498Szrj 	      && scope != file_scope
124638fd1498Szrj 	      && scope != external_scope)
124738fd1498Szrj 	    {
124838fd1498Szrj 	      error ("nested function %q+D declared but never defined", p);
124938fd1498Szrj 	      undef_nested_function = true;
125038fd1498Szrj 	    }
125138fd1498Szrj 	  else if (DECL_DECLARED_INLINE_P (p)
125238fd1498Szrj 		   && TREE_PUBLIC (p)
125338fd1498Szrj 		   && !DECL_INITIAL (p))
125438fd1498Szrj 	    {
125538fd1498Szrj 	      /* C99 6.7.4p6: "a function with external linkage... declared
125638fd1498Szrj 		 with an inline function specifier ... shall also be defined
125738fd1498Szrj 		 in the same translation unit."  */
125838fd1498Szrj 	      if (!flag_gnu89_inline
125938fd1498Szrj 		  && !lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (p))
1260*58e805e6Szrj 		  && scope == external_scope)
126138fd1498Szrj 		pedwarn (input_location, 0,
126238fd1498Szrj 			 "inline function %q+D declared but never defined", p);
126338fd1498Szrj 	      DECL_EXTERNAL (p) = 1;
126438fd1498Szrj 	    }
126538fd1498Szrj 
126638fd1498Szrj 	  goto common_symbol;
126738fd1498Szrj 
126838fd1498Szrj 	case VAR_DECL:
126938fd1498Szrj 	  /* Warnings for unused variables.  */
127038fd1498Szrj 	  if ((!TREE_USED (p) || !DECL_READ_P (p))
127138fd1498Szrj 	      && !TREE_NO_WARNING (p)
127238fd1498Szrj 	      && !DECL_IN_SYSTEM_HEADER (p)
127338fd1498Szrj 	      && DECL_NAME (p)
127438fd1498Szrj 	      && !DECL_ARTIFICIAL (p)
127538fd1498Szrj 	      && scope != file_scope
127638fd1498Szrj 	      && scope != external_scope)
127738fd1498Szrj 	    {
127838fd1498Szrj 	      if (!TREE_USED (p))
127938fd1498Szrj 		warning (OPT_Wunused_variable, "unused variable %q+D", p);
128038fd1498Szrj 	      else if (DECL_CONTEXT (p) == current_function_decl)
128138fd1498Szrj 		warning_at (DECL_SOURCE_LOCATION (p),
128238fd1498Szrj 			    OPT_Wunused_but_set_variable,
128338fd1498Szrj 			    "variable %qD set but not used", p);
128438fd1498Szrj 	    }
128538fd1498Szrj 
128638fd1498Szrj 	  if (b->inner_comp)
128738fd1498Szrj 	    {
128838fd1498Szrj 	      error ("type of array %q+D completed incompatibly with"
128938fd1498Szrj 		     " implicit initialization", p);
129038fd1498Szrj 	    }
129138fd1498Szrj 
129238fd1498Szrj 	  /* Fall through.  */
129338fd1498Szrj 	case TYPE_DECL:
129438fd1498Szrj 	case CONST_DECL:
129538fd1498Szrj 	common_symbol:
129638fd1498Szrj 	  /* All of these go in BLOCK_VARS, but only if this is the
129738fd1498Szrj 	     binding in the home scope.  */
129838fd1498Szrj 	  if (!b->nested)
129938fd1498Szrj 	    {
130038fd1498Szrj 	      DECL_CHAIN (p) = BLOCK_VARS (block);
130138fd1498Szrj 	      BLOCK_VARS (block) = p;
130238fd1498Szrj 	    }
130338fd1498Szrj 	  else if (VAR_OR_FUNCTION_DECL_P (p) && scope != file_scope)
130438fd1498Szrj 	    {
130538fd1498Szrj 	      /* For block local externs add a special
130638fd1498Szrj 		 DECL_EXTERNAL decl for debug info generation.  */
130738fd1498Szrj 	      tree extp = copy_node (p);
130838fd1498Szrj 
130938fd1498Szrj 	      DECL_EXTERNAL (extp) = 1;
131038fd1498Szrj 	      TREE_STATIC (extp) = 0;
131138fd1498Szrj 	      TREE_PUBLIC (extp) = 1;
131238fd1498Szrj 	      DECL_INITIAL (extp) = NULL_TREE;
131338fd1498Szrj 	      DECL_LANG_SPECIFIC (extp) = NULL;
131438fd1498Szrj 	      DECL_CONTEXT (extp) = current_function_decl;
131538fd1498Szrj 	      if (TREE_CODE (p) == FUNCTION_DECL)
131638fd1498Szrj 		{
131738fd1498Szrj 		  DECL_RESULT (extp) = NULL_TREE;
131838fd1498Szrj 		  DECL_SAVED_TREE (extp) = NULL_TREE;
131938fd1498Szrj 		  DECL_STRUCT_FUNCTION (extp) = NULL;
132038fd1498Szrj 		}
132138fd1498Szrj 	      if (b->locus != UNKNOWN_LOCATION)
132238fd1498Szrj 		DECL_SOURCE_LOCATION (extp) = b->locus;
132338fd1498Szrj 	      DECL_CHAIN (extp) = BLOCK_VARS (block);
132438fd1498Szrj 	      BLOCK_VARS (block) = extp;
132538fd1498Szrj 	    }
132638fd1498Szrj 	  /* If this is the file scope set DECL_CONTEXT of each decl to
132738fd1498Szrj 	     the TRANSLATION_UNIT_DECL.  This makes same_translation_unit_p
132838fd1498Szrj 	     work.  */
132938fd1498Szrj 	  if (scope == file_scope)
133038fd1498Szrj 	    {
133138fd1498Szrj 	      DECL_CONTEXT (p) = context;
133238fd1498Szrj 	      if (TREE_CODE (p) == TYPE_DECL
133338fd1498Szrj 		  && TREE_TYPE (p) != error_mark_node)
133438fd1498Szrj 		set_type_context (TREE_TYPE (p), context);
133538fd1498Szrj 	    }
133638fd1498Szrj 
133738fd1498Szrj 	  gcc_fallthrough ();
133838fd1498Szrj 	  /* Parameters go in DECL_ARGUMENTS, not BLOCK_VARS, and have
133938fd1498Szrj 	     already been put there by store_parm_decls.  Unused-
134038fd1498Szrj 	     parameter warnings are handled by function.c.
134138fd1498Szrj 	     error_mark_node obviously does not go in BLOCK_VARS and
134238fd1498Szrj 	     does not get unused-variable warnings.  */
134338fd1498Szrj 	case PARM_DECL:
134438fd1498Szrj 	case ERROR_MARK:
134538fd1498Szrj 	  /* It is possible for a decl not to have a name.  We get
134638fd1498Szrj 	     here with b->id NULL in this case.  */
134738fd1498Szrj 	  if (b->id)
134838fd1498Szrj 	    {
134938fd1498Szrj 	      gcc_assert (I_SYMBOL_BINDING (b->id) == b);
135038fd1498Szrj 	      I_SYMBOL_BINDING (b->id) = b->shadowed;
135138fd1498Szrj 	      if (b->shadowed && b->shadowed->u.type)
135238fd1498Szrj 		TREE_TYPE (b->shadowed->decl) = b->shadowed->u.type;
135338fd1498Szrj 	    }
135438fd1498Szrj 	  break;
135538fd1498Szrj 
135638fd1498Szrj 	default:
135738fd1498Szrj 	  gcc_unreachable ();
135838fd1498Szrj 	}
135938fd1498Szrj     }
136038fd1498Szrj 
136138fd1498Szrj 
136238fd1498Szrj   /* Dispose of the block that we just made inside some higher level.  */
136338fd1498Szrj   if ((scope->function_body || scope == file_scope) && context)
136438fd1498Szrj     {
136538fd1498Szrj       DECL_INITIAL (context) = block;
136638fd1498Szrj       BLOCK_SUPERCONTEXT (block) = context;
136738fd1498Szrj     }
136838fd1498Szrj   else if (scope->outer)
136938fd1498Szrj     {
137038fd1498Szrj       if (block)
137138fd1498Szrj 	SCOPE_LIST_APPEND (scope->outer, blocks, block);
137238fd1498Szrj       /* If we did not make a block for the scope just exited, any
137338fd1498Szrj 	 blocks made for inner scopes must be carried forward so they
137438fd1498Szrj 	 will later become subblocks of something else.  */
137538fd1498Szrj       else if (scope->blocks)
137638fd1498Szrj 	SCOPE_LIST_CONCAT (scope->outer, blocks, scope, blocks);
137738fd1498Szrj     }
137838fd1498Szrj 
137938fd1498Szrj   /* Pop the current scope, and free the structure for reuse.  */
138038fd1498Szrj   current_scope = scope->outer;
138138fd1498Szrj   if (scope->function_body)
138238fd1498Szrj     current_function_scope = scope->outer_function;
138338fd1498Szrj 
138438fd1498Szrj   memset (scope, 0, sizeof (struct c_scope));
138538fd1498Szrj   scope->outer = scope_freelist;
138638fd1498Szrj   scope_freelist = scope;
138738fd1498Szrj 
138838fd1498Szrj   return block;
138938fd1498Szrj }
139038fd1498Szrj 
139138fd1498Szrj void
push_file_scope(void)139238fd1498Szrj push_file_scope (void)
139338fd1498Szrj {
139438fd1498Szrj   tree decl;
139538fd1498Szrj 
139638fd1498Szrj   if (file_scope)
139738fd1498Szrj     return;
139838fd1498Szrj 
139938fd1498Szrj   push_scope ();
140038fd1498Szrj   file_scope = current_scope;
140138fd1498Szrj 
140238fd1498Szrj   start_fname_decls ();
140338fd1498Szrj 
140438fd1498Szrj   for (decl = visible_builtins; decl; decl = DECL_CHAIN (decl))
140538fd1498Szrj     bind (DECL_NAME (decl), decl, file_scope,
140638fd1498Szrj 	  /*invisible=*/false, /*nested=*/true, DECL_SOURCE_LOCATION (decl));
140738fd1498Szrj }
140838fd1498Szrj 
140938fd1498Szrj void
pop_file_scope(void)141038fd1498Szrj pop_file_scope (void)
141138fd1498Szrj {
141238fd1498Szrj   /* In case there were missing closebraces, get us back to the global
141338fd1498Szrj      binding level.  */
141438fd1498Szrj   while (current_scope != file_scope)
141538fd1498Szrj     pop_scope ();
141638fd1498Szrj 
141738fd1498Szrj   /* __FUNCTION__ is defined at file scope ("").  This
141838fd1498Szrj      call may not be necessary as my tests indicate it
141938fd1498Szrj      still works without it.  */
142038fd1498Szrj   finish_fname_decls ();
142138fd1498Szrj 
142238fd1498Szrj   check_inline_statics ();
142338fd1498Szrj 
142438fd1498Szrj   /* This is the point to write out a PCH if we're doing that.
142538fd1498Szrj      In that case we do not want to do anything else.  */
142638fd1498Szrj   if (pch_file)
142738fd1498Szrj     {
142838fd1498Szrj       c_common_write_pch ();
142938fd1498Szrj       /* Ensure even the callers don't try to finalize the CU.  */
143038fd1498Szrj       flag_syntax_only = 1;
143138fd1498Szrj       return;
143238fd1498Szrj     }
143338fd1498Szrj 
143438fd1498Szrj   /* Pop off the file scope and close this translation unit.  */
143538fd1498Szrj   pop_scope ();
143638fd1498Szrj   file_scope = 0;
143738fd1498Szrj 
143838fd1498Szrj   maybe_apply_pending_pragma_weaks ();
143938fd1498Szrj }
144038fd1498Szrj 
144138fd1498Szrj /* Adjust the bindings for the start of a statement expression.  */
144238fd1498Szrj 
144338fd1498Szrj void
c_bindings_start_stmt_expr(struct c_spot_bindings * switch_bindings)144438fd1498Szrj c_bindings_start_stmt_expr (struct c_spot_bindings* switch_bindings)
144538fd1498Szrj {
144638fd1498Szrj   struct c_scope *scope;
144738fd1498Szrj 
144838fd1498Szrj   for (scope = current_scope; scope != NULL; scope = scope->outer)
144938fd1498Szrj     {
145038fd1498Szrj       struct c_binding *b;
145138fd1498Szrj 
145238fd1498Szrj       if (!scope->has_label_bindings)
145338fd1498Szrj 	continue;
145438fd1498Szrj 
145538fd1498Szrj       for (b = scope->bindings; b != NULL; b = b->prev)
145638fd1498Szrj 	{
145738fd1498Szrj 	  struct c_label_vars *label_vars;
145838fd1498Szrj 	  unsigned int ix;
145938fd1498Szrj 	  struct c_goto_bindings *g;
146038fd1498Szrj 
146138fd1498Szrj 	  if (TREE_CODE (b->decl) != LABEL_DECL)
146238fd1498Szrj 	    continue;
146338fd1498Szrj 	  label_vars = b->u.label;
146438fd1498Szrj 	  ++label_vars->label_bindings.stmt_exprs;
146538fd1498Szrj 	  FOR_EACH_VEC_SAFE_ELT (label_vars->gotos, ix, g)
146638fd1498Szrj 	    ++g->goto_bindings.stmt_exprs;
146738fd1498Szrj 	}
146838fd1498Szrj     }
146938fd1498Szrj 
147038fd1498Szrj   if (switch_bindings != NULL)
147138fd1498Szrj     ++switch_bindings->stmt_exprs;
147238fd1498Szrj }
147338fd1498Szrj 
147438fd1498Szrj /* Adjust the bindings for the end of a statement expression.  */
147538fd1498Szrj 
147638fd1498Szrj void
c_bindings_end_stmt_expr(struct c_spot_bindings * switch_bindings)147738fd1498Szrj c_bindings_end_stmt_expr (struct c_spot_bindings *switch_bindings)
147838fd1498Szrj {
147938fd1498Szrj   struct c_scope *scope;
148038fd1498Szrj 
148138fd1498Szrj   for (scope = current_scope; scope != NULL; scope = scope->outer)
148238fd1498Szrj     {
148338fd1498Szrj       struct c_binding *b;
148438fd1498Szrj 
148538fd1498Szrj       if (!scope->has_label_bindings)
148638fd1498Szrj 	continue;
148738fd1498Szrj 
148838fd1498Szrj       for (b = scope->bindings; b != NULL; b = b->prev)
148938fd1498Szrj 	{
149038fd1498Szrj 	  struct c_label_vars *label_vars;
149138fd1498Szrj 	  unsigned int ix;
149238fd1498Szrj 	  struct c_goto_bindings *g;
149338fd1498Szrj 
149438fd1498Szrj 	  if (TREE_CODE (b->decl) != LABEL_DECL)
149538fd1498Szrj 	    continue;
149638fd1498Szrj 	  label_vars = b->u.label;
149738fd1498Szrj 	  --label_vars->label_bindings.stmt_exprs;
149838fd1498Szrj 	  if (label_vars->label_bindings.stmt_exprs < 0)
149938fd1498Szrj 	    {
150038fd1498Szrj 	      label_vars->label_bindings.left_stmt_expr = true;
150138fd1498Szrj 	      label_vars->label_bindings.stmt_exprs = 0;
150238fd1498Szrj 	    }
150338fd1498Szrj 	  FOR_EACH_VEC_SAFE_ELT (label_vars->gotos, ix, g)
150438fd1498Szrj 	    {
150538fd1498Szrj 	      --g->goto_bindings.stmt_exprs;
150638fd1498Szrj 	      if (g->goto_bindings.stmt_exprs < 0)
150738fd1498Szrj 		{
150838fd1498Szrj 		  g->goto_bindings.left_stmt_expr = true;
150938fd1498Szrj 		  g->goto_bindings.stmt_exprs = 0;
151038fd1498Szrj 		}
151138fd1498Szrj 	    }
151238fd1498Szrj 	}
151338fd1498Szrj     }
151438fd1498Szrj 
151538fd1498Szrj   if (switch_bindings != NULL)
151638fd1498Szrj     {
151738fd1498Szrj       --switch_bindings->stmt_exprs;
151838fd1498Szrj       gcc_assert (switch_bindings->stmt_exprs >= 0);
151938fd1498Szrj     }
152038fd1498Szrj }
152138fd1498Szrj 
152238fd1498Szrj /* Push a definition or a declaration of struct, union or enum tag "name".
152338fd1498Szrj    "type" should be the type node.
152438fd1498Szrj    We assume that the tag "name" is not already defined, and has a location
152538fd1498Szrj    of LOC.
152638fd1498Szrj 
152738fd1498Szrj    Note that the definition may really be just a forward reference.
152838fd1498Szrj    In that case, the TYPE_SIZE will be zero.  */
152938fd1498Szrj 
153038fd1498Szrj static void
pushtag(location_t loc,tree name,tree type)153138fd1498Szrj pushtag (location_t loc, tree name, tree type)
153238fd1498Szrj {
153338fd1498Szrj   /* Record the identifier as the type's name if it has none.  */
153438fd1498Szrj   if (name && !TYPE_NAME (type))
153538fd1498Szrj     TYPE_NAME (type) = name;
153638fd1498Szrj   bind (name, type, current_scope, /*invisible=*/false, /*nested=*/false, loc);
153738fd1498Szrj 
153838fd1498Szrj   /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the
153938fd1498Szrj      tagged type we just added to the current scope.  This fake
154038fd1498Szrj      NULL-named TYPE_DECL node helps dwarfout.c to know when it needs
154138fd1498Szrj      to output a representation of a tagged type, and it also gives
154238fd1498Szrj      us a convenient place to record the "scope start" address for the
154338fd1498Szrj      tagged type.  */
154438fd1498Szrj 
154538fd1498Szrj   TYPE_STUB_DECL (type) = pushdecl (build_decl (loc,
154638fd1498Szrj 						TYPE_DECL, NULL_TREE, type));
154738fd1498Szrj 
154838fd1498Szrj   /* An approximation for now, so we can tell this is a function-scope tag.
154938fd1498Szrj      This will be updated in pop_scope.  */
155038fd1498Szrj   TYPE_CONTEXT (type) = DECL_CONTEXT (TYPE_STUB_DECL (type));
155138fd1498Szrj 
155238fd1498Szrj   if (warn_cxx_compat && name != NULL_TREE)
155338fd1498Szrj     {
155438fd1498Szrj       struct c_binding *b = I_SYMBOL_BINDING (name);
155538fd1498Szrj 
155638fd1498Szrj       if (b != NULL
155738fd1498Szrj 	  && b->decl != NULL_TREE
155838fd1498Szrj 	  && TREE_CODE (b->decl) == TYPE_DECL
155938fd1498Szrj 	  && (B_IN_CURRENT_SCOPE (b)
156038fd1498Szrj 	      || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
156138fd1498Szrj 	  && (TYPE_MAIN_VARIANT (TREE_TYPE (b->decl))
156238fd1498Szrj 	      != TYPE_MAIN_VARIANT (type)))
156338fd1498Szrj 	{
156438fd1498Szrj 	  if (warning_at (loc, OPT_Wc___compat,
156538fd1498Szrj 			  ("using %qD as both a typedef and a tag is "
156638fd1498Szrj 			   "invalid in C++"), b->decl)
156738fd1498Szrj 	      && b->locus != UNKNOWN_LOCATION)
156838fd1498Szrj 	    inform (b->locus, "originally defined here");
156938fd1498Szrj 	}
157038fd1498Szrj     }
157138fd1498Szrj }
157238fd1498Szrj 
157338fd1498Szrj /* An exported interface to pushtag.  This is used by the gdb plugin's
157438fd1498Szrj    binding oracle to introduce a new tag binding.  */
157538fd1498Szrj 
157638fd1498Szrj void
c_pushtag(location_t loc,tree name,tree type)157738fd1498Szrj c_pushtag (location_t loc, tree name, tree type)
157838fd1498Szrj {
157938fd1498Szrj   pushtag (loc, name, type);
158038fd1498Szrj }
158138fd1498Szrj 
158238fd1498Szrj /* An exported interface to bind a declaration.  LOC is the location
158338fd1498Szrj    to use.  DECL is the declaration to bind.  The decl's name is used
158438fd1498Szrj    to determine how it is bound.  If DECL is a VAR_DECL, then
158538fd1498Szrj    IS_GLOBAL determines whether the decl is put into the global (file
158638fd1498Szrj    and external) scope or the current function's scope; if DECL is not
158738fd1498Szrj    a VAR_DECL then it is always put into the file scope.  */
158838fd1498Szrj 
158938fd1498Szrj void
c_bind(location_t loc,tree decl,bool is_global)159038fd1498Szrj c_bind (location_t loc, tree decl, bool is_global)
159138fd1498Szrj {
159238fd1498Szrj   struct c_scope *scope;
159338fd1498Szrj   bool nested = false;
159438fd1498Szrj 
159538fd1498Szrj   if (!VAR_P (decl) || current_function_scope == NULL)
159638fd1498Szrj     {
159738fd1498Szrj       /* Types and functions are always considered to be global.  */
159838fd1498Szrj       scope = file_scope;
159938fd1498Szrj       DECL_EXTERNAL (decl) = 1;
160038fd1498Szrj       TREE_PUBLIC (decl) = 1;
160138fd1498Szrj     }
160238fd1498Szrj   else if (is_global)
160338fd1498Szrj     {
160438fd1498Szrj       /* Also bind it into the external scope.  */
160538fd1498Szrj       bind (DECL_NAME (decl), decl, external_scope, true, false, loc);
160638fd1498Szrj       nested = true;
160738fd1498Szrj       scope = file_scope;
160838fd1498Szrj       DECL_EXTERNAL (decl) = 1;
160938fd1498Szrj       TREE_PUBLIC (decl) = 1;
161038fd1498Szrj     }
161138fd1498Szrj   else
161238fd1498Szrj     {
161338fd1498Szrj       DECL_CONTEXT (decl) = current_function_decl;
161438fd1498Szrj       TREE_PUBLIC (decl) = 0;
161538fd1498Szrj       scope = current_function_scope;
161638fd1498Szrj     }
161738fd1498Szrj 
161838fd1498Szrj   bind (DECL_NAME (decl), decl, scope, false, nested, loc);
161938fd1498Szrj }
162038fd1498Szrj 
162138fd1498Szrj /* Subroutine of compare_decls.  Allow harmless mismatches in return
162238fd1498Szrj    and argument types provided that the type modes match.  This function
162338fd1498Szrj    return a unified type given a suitable match, and 0 otherwise.  */
162438fd1498Szrj 
162538fd1498Szrj static tree
match_builtin_function_types(tree newtype,tree oldtype)162638fd1498Szrj match_builtin_function_types (tree newtype, tree oldtype)
162738fd1498Szrj {
162838fd1498Szrj   tree newrettype, oldrettype;
162938fd1498Szrj   tree newargs, oldargs;
163038fd1498Szrj   tree trytype, tryargs;
163138fd1498Szrj 
163238fd1498Szrj   /* Accept the return type of the new declaration if same modes.  */
163338fd1498Szrj   oldrettype = TREE_TYPE (oldtype);
163438fd1498Szrj   newrettype = TREE_TYPE (newtype);
163538fd1498Szrj 
163638fd1498Szrj   if (TYPE_MODE (oldrettype) != TYPE_MODE (newrettype))
163738fd1498Szrj     return NULL_TREE;
163838fd1498Szrj 
163938fd1498Szrj   oldargs = TYPE_ARG_TYPES (oldtype);
164038fd1498Szrj   newargs = TYPE_ARG_TYPES (newtype);
164138fd1498Szrj   tryargs = newargs;
164238fd1498Szrj 
164338fd1498Szrj   while (oldargs || newargs)
164438fd1498Szrj     {
164538fd1498Szrj       if (!oldargs
164638fd1498Szrj 	  || !newargs
164738fd1498Szrj 	  || !TREE_VALUE (oldargs)
164838fd1498Szrj 	  || !TREE_VALUE (newargs)
164938fd1498Szrj 	  || TYPE_MODE (TREE_VALUE (oldargs))
165038fd1498Szrj 	     != TYPE_MODE (TREE_VALUE (newargs)))
165138fd1498Szrj 	return NULL_TREE;
165238fd1498Szrj 
165338fd1498Szrj       oldargs = TREE_CHAIN (oldargs);
165438fd1498Szrj       newargs = TREE_CHAIN (newargs);
165538fd1498Szrj     }
165638fd1498Szrj 
165738fd1498Szrj   trytype = build_function_type (newrettype, tryargs);
165838fd1498Szrj 
165938fd1498Szrj   /* Allow declaration to change transaction_safe attribute.  */
166038fd1498Szrj   tree oldattrs = TYPE_ATTRIBUTES (oldtype);
166138fd1498Szrj   tree oldtsafe = lookup_attribute ("transaction_safe", oldattrs);
166238fd1498Szrj   tree newattrs = TYPE_ATTRIBUTES (newtype);
166338fd1498Szrj   tree newtsafe = lookup_attribute ("transaction_safe", newattrs);
166438fd1498Szrj   if (oldtsafe && !newtsafe)
166538fd1498Szrj     oldattrs = remove_attribute ("transaction_safe", oldattrs);
166638fd1498Szrj   else if (newtsafe && !oldtsafe)
166738fd1498Szrj     oldattrs = tree_cons (get_identifier ("transaction_safe"),
166838fd1498Szrj 			  NULL_TREE, oldattrs);
166938fd1498Szrj 
167038fd1498Szrj   return build_type_attribute_variant (trytype, oldattrs);
167138fd1498Szrj }
167238fd1498Szrj 
167338fd1498Szrj /* Subroutine of diagnose_mismatched_decls.  Check for function type
167438fd1498Szrj    mismatch involving an empty arglist vs a nonempty one and give clearer
167538fd1498Szrj    diagnostics.  */
167638fd1498Szrj static void
diagnose_arglist_conflict(tree newdecl,tree olddecl,tree newtype,tree oldtype)167738fd1498Szrj diagnose_arglist_conflict (tree newdecl, tree olddecl,
167838fd1498Szrj 			   tree newtype, tree oldtype)
167938fd1498Szrj {
168038fd1498Szrj   tree t;
168138fd1498Szrj 
168238fd1498Szrj   if (TREE_CODE (olddecl) != FUNCTION_DECL
168338fd1498Szrj       || !comptypes (TREE_TYPE (oldtype), TREE_TYPE (newtype))
168438fd1498Szrj       || !((!prototype_p (oldtype) && DECL_INITIAL (olddecl) == NULL_TREE)
168538fd1498Szrj 	   || (!prototype_p (newtype) && DECL_INITIAL (newdecl) == NULL_TREE)))
168638fd1498Szrj     return;
168738fd1498Szrj 
168838fd1498Szrj   t = TYPE_ARG_TYPES (oldtype);
168938fd1498Szrj   if (t == NULL_TREE)
169038fd1498Szrj     t = TYPE_ARG_TYPES (newtype);
169138fd1498Szrj   for (; t; t = TREE_CHAIN (t))
169238fd1498Szrj     {
169338fd1498Szrj       tree type = TREE_VALUE (t);
169438fd1498Szrj 
169538fd1498Szrj       if (TREE_CHAIN (t) == NULL_TREE
169638fd1498Szrj 	  && TYPE_MAIN_VARIANT (type) != void_type_node)
169738fd1498Szrj 	{
169838fd1498Szrj 	  inform (input_location, "a parameter list with an ellipsis can%'t match "
169938fd1498Szrj 		  "an empty parameter name list declaration");
170038fd1498Szrj 	  break;
170138fd1498Szrj 	}
170238fd1498Szrj 
170338fd1498Szrj       if (c_type_promotes_to (type) != type)
170438fd1498Szrj 	{
170538fd1498Szrj 	  inform (input_location, "an argument type that has a default promotion can%'t match "
170638fd1498Szrj 		  "an empty parameter name list declaration");
170738fd1498Szrj 	  break;
170838fd1498Szrj 	}
170938fd1498Szrj     }
171038fd1498Szrj }
171138fd1498Szrj 
171238fd1498Szrj /* Another subroutine of diagnose_mismatched_decls.  OLDDECL is an
171338fd1498Szrj    old-style function definition, NEWDECL is a prototype declaration.
171438fd1498Szrj    Diagnose inconsistencies in the argument list.  Returns TRUE if
171538fd1498Szrj    the prototype is compatible, FALSE if not.  */
171638fd1498Szrj static bool
validate_proto_after_old_defn(tree newdecl,tree newtype,tree oldtype)171738fd1498Szrj validate_proto_after_old_defn (tree newdecl, tree newtype, tree oldtype)
171838fd1498Szrj {
171938fd1498Szrj   tree newargs, oldargs;
172038fd1498Szrj   int i;
172138fd1498Szrj 
172238fd1498Szrj #define END_OF_ARGLIST(t) ((t) == void_type_node)
172338fd1498Szrj 
172438fd1498Szrj   oldargs = TYPE_ACTUAL_ARG_TYPES (oldtype);
172538fd1498Szrj   newargs = TYPE_ARG_TYPES (newtype);
172638fd1498Szrj   i = 1;
172738fd1498Szrj 
172838fd1498Szrj   for (;;)
172938fd1498Szrj     {
173038fd1498Szrj       tree oldargtype = TREE_VALUE (oldargs);
173138fd1498Szrj       tree newargtype = TREE_VALUE (newargs);
173238fd1498Szrj 
173338fd1498Szrj       if (oldargtype == error_mark_node || newargtype == error_mark_node)
173438fd1498Szrj 	return false;
173538fd1498Szrj 
173638fd1498Szrj       oldargtype = (TYPE_ATOMIC (oldargtype)
173738fd1498Szrj 		    ? c_build_qualified_type (TYPE_MAIN_VARIANT (oldargtype),
173838fd1498Szrj 					      TYPE_QUAL_ATOMIC)
173938fd1498Szrj 		    : TYPE_MAIN_VARIANT (oldargtype));
174038fd1498Szrj       newargtype = (TYPE_ATOMIC (newargtype)
174138fd1498Szrj 		    ? c_build_qualified_type (TYPE_MAIN_VARIANT (newargtype),
174238fd1498Szrj 					      TYPE_QUAL_ATOMIC)
174338fd1498Szrj 		    : TYPE_MAIN_VARIANT (newargtype));
174438fd1498Szrj 
174538fd1498Szrj       if (END_OF_ARGLIST (oldargtype) && END_OF_ARGLIST (newargtype))
174638fd1498Szrj 	break;
174738fd1498Szrj 
174838fd1498Szrj       /* Reaching the end of just one list means the two decls don't
174938fd1498Szrj 	 agree on the number of arguments.  */
175038fd1498Szrj       if (END_OF_ARGLIST (oldargtype))
175138fd1498Szrj 	{
175238fd1498Szrj 	  error ("prototype for %q+D declares more arguments "
175338fd1498Szrj 		 "than previous old-style definition", newdecl);
175438fd1498Szrj 	  return false;
175538fd1498Szrj 	}
175638fd1498Szrj       else if (END_OF_ARGLIST (newargtype))
175738fd1498Szrj 	{
175838fd1498Szrj 	  error ("prototype for %q+D declares fewer arguments "
175938fd1498Szrj 		 "than previous old-style definition", newdecl);
176038fd1498Szrj 	  return false;
176138fd1498Szrj 	}
176238fd1498Szrj 
176338fd1498Szrj       /* Type for passing arg must be consistent with that declared
176438fd1498Szrj 	 for the arg.  */
176538fd1498Szrj       else if (!comptypes (oldargtype, newargtype))
176638fd1498Szrj 	{
176738fd1498Szrj 	  error ("prototype for %q+D declares argument %d"
176838fd1498Szrj 		 " with incompatible type",
176938fd1498Szrj 		 newdecl, i);
177038fd1498Szrj 	  return false;
177138fd1498Szrj 	}
177238fd1498Szrj 
177338fd1498Szrj       oldargs = TREE_CHAIN (oldargs);
177438fd1498Szrj       newargs = TREE_CHAIN (newargs);
177538fd1498Szrj       i++;
177638fd1498Szrj     }
177738fd1498Szrj 
177838fd1498Szrj   /* If we get here, no errors were found, but do issue a warning
177938fd1498Szrj      for this poor-style construct.  */
178038fd1498Szrj   warning (0, "prototype for %q+D follows non-prototype definition",
178138fd1498Szrj 	   newdecl);
178238fd1498Szrj   return true;
178338fd1498Szrj #undef END_OF_ARGLIST
178438fd1498Szrj }
178538fd1498Szrj 
178638fd1498Szrj /* Subroutine of diagnose_mismatched_decls.  Report the location of DECL,
178738fd1498Szrj    first in a pair of mismatched declarations, using the diagnostic
178838fd1498Szrj    function DIAG.  */
178938fd1498Szrj static void
locate_old_decl(tree decl)179038fd1498Szrj locate_old_decl (tree decl)
179138fd1498Szrj {
179238fd1498Szrj   if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl)
179338fd1498Szrj       && !C_DECL_DECLARED_BUILTIN (decl))
179438fd1498Szrj     ;
179538fd1498Szrj   else if (DECL_INITIAL (decl))
179638fd1498Szrj     inform (input_location, "previous definition of %q+D was here", decl);
179738fd1498Szrj   else if (C_DECL_IMPLICIT (decl))
179838fd1498Szrj     inform (input_location, "previous implicit declaration of %q+D was here", decl);
179938fd1498Szrj   else
180038fd1498Szrj     inform (input_location, "previous declaration of %q+D was here", decl);
180138fd1498Szrj }
180238fd1498Szrj 
180338fd1498Szrj /* Subroutine of duplicate_decls.  Compare NEWDECL to OLDDECL.
180438fd1498Szrj    Returns true if the caller should proceed to merge the two, false
180538fd1498Szrj    if OLDDECL should simply be discarded.  As a side effect, issues
180638fd1498Szrj    all necessary diagnostics for invalid or poor-style combinations.
180738fd1498Szrj    If it returns true, writes the types of NEWDECL and OLDDECL to
180838fd1498Szrj    *NEWTYPEP and *OLDTYPEP - these may have been adjusted from
180938fd1498Szrj    TREE_TYPE (NEWDECL, OLDDECL) respectively.  */
181038fd1498Szrj 
181138fd1498Szrj static bool
diagnose_mismatched_decls(tree newdecl,tree olddecl,tree * newtypep,tree * oldtypep)181238fd1498Szrj diagnose_mismatched_decls (tree newdecl, tree olddecl,
181338fd1498Szrj 			   tree *newtypep, tree *oldtypep)
181438fd1498Szrj {
181538fd1498Szrj   tree newtype, oldtype;
181638fd1498Szrj   bool pedwarned = false;
181738fd1498Szrj   bool warned = false;
181838fd1498Szrj   bool retval = true;
181938fd1498Szrj 
182038fd1498Szrj #define DECL_EXTERN_INLINE(DECL) (DECL_DECLARED_INLINE_P (DECL)  \
182138fd1498Szrj 				  && DECL_EXTERNAL (DECL))
182238fd1498Szrj 
182338fd1498Szrj   /* If we have error_mark_node for either decl or type, just discard
182438fd1498Szrj      the previous decl - we're in an error cascade already.  */
182538fd1498Szrj   if (olddecl == error_mark_node || newdecl == error_mark_node)
182638fd1498Szrj     return false;
182738fd1498Szrj   *oldtypep = oldtype = TREE_TYPE (olddecl);
182838fd1498Szrj   *newtypep = newtype = TREE_TYPE (newdecl);
182938fd1498Szrj   if (oldtype == error_mark_node || newtype == error_mark_node)
183038fd1498Szrj     return false;
183138fd1498Szrj 
183238fd1498Szrj   /* Two different categories of symbol altogether.  This is an error
183338fd1498Szrj      unless OLDDECL is a builtin.  OLDDECL will be discarded in any case.  */
183438fd1498Szrj   if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
183538fd1498Szrj     {
183638fd1498Szrj       if (!(TREE_CODE (olddecl) == FUNCTION_DECL
183738fd1498Szrj 	    && DECL_BUILT_IN (olddecl)
183838fd1498Szrj 	    && !C_DECL_DECLARED_BUILTIN (olddecl)))
183938fd1498Szrj 	{
184038fd1498Szrj 	  error ("%q+D redeclared as different kind of symbol", newdecl);
184138fd1498Szrj 	  locate_old_decl (olddecl);
184238fd1498Szrj 	}
184338fd1498Szrj       else if (TREE_PUBLIC (newdecl))
184438fd1498Szrj 	warning (OPT_Wbuiltin_declaration_mismatch,
184538fd1498Szrj 		 "built-in function %q+D declared as non-function",
184638fd1498Szrj 		 newdecl);
184738fd1498Szrj       else
184838fd1498Szrj 	warning (OPT_Wshadow, "declaration of %q+D shadows "
184938fd1498Szrj 		 "a built-in function", newdecl);
185038fd1498Szrj       return false;
185138fd1498Szrj     }
185238fd1498Szrj 
185338fd1498Szrj   /* Enumerators have no linkage, so may only be declared once in a
185438fd1498Szrj      given scope.  */
185538fd1498Szrj   if (TREE_CODE (olddecl) == CONST_DECL)
185638fd1498Szrj     {
185738fd1498Szrj       error ("redeclaration of enumerator %q+D", newdecl);
185838fd1498Szrj       locate_old_decl (olddecl);
185938fd1498Szrj       return false;
186038fd1498Szrj     }
186138fd1498Szrj 
186238fd1498Szrj   if (!comptypes (oldtype, newtype))
186338fd1498Szrj     {
186438fd1498Szrj       if (TREE_CODE (olddecl) == FUNCTION_DECL
186538fd1498Szrj 	  && DECL_BUILT_IN (olddecl) && !C_DECL_DECLARED_BUILTIN (olddecl))
186638fd1498Szrj 	{
186738fd1498Szrj 	  /* Accept harmless mismatch in function types.
186838fd1498Szrj 	     This is for the ffs and fprintf builtins.  */
186938fd1498Szrj 	  tree trytype = match_builtin_function_types (newtype, oldtype);
187038fd1498Szrj 
187138fd1498Szrj 	  if (trytype && comptypes (newtype, trytype))
187238fd1498Szrj 	    *oldtypep = oldtype = trytype;
187338fd1498Szrj 	  else
187438fd1498Szrj 	    {
187538fd1498Szrj 	      /* If types don't match for a built-in, throw away the
187638fd1498Szrj 		 built-in.  No point in calling locate_old_decl here, it
187738fd1498Szrj 		 won't print anything.  */
187838fd1498Szrj 	      warning (OPT_Wbuiltin_declaration_mismatch,
187938fd1498Szrj 		       "conflicting types for built-in function %q+D",
188038fd1498Szrj 		       newdecl);
188138fd1498Szrj 	      return false;
188238fd1498Szrj 	    }
188338fd1498Szrj 	}
188438fd1498Szrj       else if (TREE_CODE (olddecl) == FUNCTION_DECL
188538fd1498Szrj 	       && DECL_IS_BUILTIN (olddecl))
188638fd1498Szrj 	{
188738fd1498Szrj 	  /* A conflicting function declaration for a predeclared
188838fd1498Szrj 	     function that isn't actually built in.  Objective C uses
188938fd1498Szrj 	     these.  The new declaration silently overrides everything
189038fd1498Szrj 	     but the volatility (i.e. noreturn) indication.  See also
189138fd1498Szrj 	     below.  FIXME: Make Objective C use normal builtins.  */
189238fd1498Szrj 	  TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
189338fd1498Szrj 	  return false;
189438fd1498Szrj 	}
189538fd1498Szrj       /* Permit void foo (...) to match int foo (...) if the latter is
189638fd1498Szrj 	 the definition and implicit int was used.  See
189738fd1498Szrj 	 c-torture/compile/920625-2.c.  */
189838fd1498Szrj       else if (TREE_CODE (newdecl) == FUNCTION_DECL && DECL_INITIAL (newdecl)
189938fd1498Szrj 	       && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == void_type_node
190038fd1498Szrj 	       && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == integer_type_node
190138fd1498Szrj 	       && C_FUNCTION_IMPLICIT_INT (newdecl) && !DECL_INITIAL (olddecl))
190238fd1498Szrj 	{
190338fd1498Szrj 	  pedwarned = pedwarn (input_location, 0,
190438fd1498Szrj 			       "conflicting types for %q+D", newdecl);
190538fd1498Szrj 	  /* Make sure we keep void as the return type.  */
190638fd1498Szrj 	  TREE_TYPE (newdecl) = *newtypep = newtype = oldtype;
190738fd1498Szrj 	  C_FUNCTION_IMPLICIT_INT (newdecl) = 0;
190838fd1498Szrj 	}
190938fd1498Szrj       /* Permit void foo (...) to match an earlier call to foo (...) with
191038fd1498Szrj 	 no declared type (thus, implicitly int).  */
191138fd1498Szrj       else if (TREE_CODE (newdecl) == FUNCTION_DECL
191238fd1498Szrj 	       && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == void_type_node
191338fd1498Szrj 	       && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == integer_type_node
191438fd1498Szrj 	       && C_DECL_IMPLICIT (olddecl) && !DECL_INITIAL (olddecl))
191538fd1498Szrj 	{
191638fd1498Szrj 	  pedwarned = pedwarn (input_location, 0,
191738fd1498Szrj 			       "conflicting types for %q+D", newdecl);
191838fd1498Szrj 	  /* Make sure we keep void as the return type.  */
191938fd1498Szrj 	  TREE_TYPE (olddecl) = *oldtypep = oldtype = newtype;
192038fd1498Szrj 	}
192138fd1498Szrj       else
192238fd1498Szrj 	{
192338fd1498Szrj 	  int new_quals = TYPE_QUALS (newtype);
192438fd1498Szrj 	  int old_quals = TYPE_QUALS (oldtype);
192538fd1498Szrj 
192638fd1498Szrj 	  if (new_quals != old_quals)
192738fd1498Szrj 	    {
192838fd1498Szrj 	      addr_space_t new_addr = DECODE_QUAL_ADDR_SPACE (new_quals);
192938fd1498Szrj 	      addr_space_t old_addr = DECODE_QUAL_ADDR_SPACE (old_quals);
193038fd1498Szrj 	      if (new_addr != old_addr)
193138fd1498Szrj 		{
193238fd1498Szrj 		  if (ADDR_SPACE_GENERIC_P (new_addr))
193338fd1498Szrj 		    error ("conflicting named address spaces (generic vs %s) "
193438fd1498Szrj 			   "for %q+D",
193538fd1498Szrj 			   c_addr_space_name (old_addr), newdecl);
193638fd1498Szrj 		  else if (ADDR_SPACE_GENERIC_P (old_addr))
193738fd1498Szrj 		    error ("conflicting named address spaces (%s vs generic) "
193838fd1498Szrj 			   "for %q+D",
193938fd1498Szrj 			   c_addr_space_name (new_addr), newdecl);
194038fd1498Szrj 		  else
194138fd1498Szrj 		    error ("conflicting named address spaces (%s vs %s) "
194238fd1498Szrj 			   "for %q+D",
194338fd1498Szrj 			   c_addr_space_name (new_addr),
194438fd1498Szrj 			   c_addr_space_name (old_addr),
194538fd1498Szrj 			   newdecl);
194638fd1498Szrj 		}
194738fd1498Szrj 
194838fd1498Szrj 	      if (CLEAR_QUAL_ADDR_SPACE (new_quals)
194938fd1498Szrj 		  != CLEAR_QUAL_ADDR_SPACE (old_quals))
195038fd1498Szrj 		error ("conflicting type qualifiers for %q+D", newdecl);
195138fd1498Szrj 	    }
195238fd1498Szrj 	  else
195338fd1498Szrj 	    error ("conflicting types for %q+D", newdecl);
195438fd1498Szrj 	  diagnose_arglist_conflict (newdecl, olddecl, newtype, oldtype);
195538fd1498Szrj 	  locate_old_decl (olddecl);
195638fd1498Szrj 	  return false;
195738fd1498Szrj 	}
195838fd1498Szrj     }
195938fd1498Szrj 
196038fd1498Szrj   /* Redeclaration of a type is a constraint violation (6.7.2.3p1),
196138fd1498Szrj      but silently ignore the redeclaration if either is in a system
196238fd1498Szrj      header.  (Conflicting redeclarations were handled above.)  This
196338fd1498Szrj      is allowed for C11 if the types are the same, not just
196438fd1498Szrj      compatible.  */
196538fd1498Szrj   if (TREE_CODE (newdecl) == TYPE_DECL)
196638fd1498Szrj     {
196738fd1498Szrj       bool types_different = false;
196838fd1498Szrj       int comptypes_result;
196938fd1498Szrj 
197038fd1498Szrj       comptypes_result
197138fd1498Szrj 	= comptypes_check_different_types (oldtype, newtype, &types_different);
197238fd1498Szrj 
197338fd1498Szrj       if (comptypes_result != 1 || types_different)
197438fd1498Szrj 	{
197538fd1498Szrj 	  error ("redefinition of typedef %q+D with different type", newdecl);
197638fd1498Szrj 	  locate_old_decl (olddecl);
197738fd1498Szrj 	  return false;
197838fd1498Szrj 	}
197938fd1498Szrj 
198038fd1498Szrj       if (DECL_IN_SYSTEM_HEADER (newdecl)
198138fd1498Szrj 	  || DECL_IN_SYSTEM_HEADER (olddecl)
198238fd1498Szrj 	  || TREE_NO_WARNING (newdecl)
198338fd1498Szrj 	  || TREE_NO_WARNING (olddecl))
198438fd1498Szrj 	return true;  /* Allow OLDDECL to continue in use.  */
198538fd1498Szrj 
198638fd1498Szrj       if (variably_modified_type_p (newtype, NULL))
198738fd1498Szrj 	{
198838fd1498Szrj 	  error ("redefinition of typedef %q+D with variably modified type",
198938fd1498Szrj 		 newdecl);
199038fd1498Szrj 	  locate_old_decl (olddecl);
199138fd1498Szrj 	}
199238fd1498Szrj       else if (pedwarn_c99 (input_location, OPT_Wpedantic,
199338fd1498Szrj 			    "redefinition of typedef %q+D", newdecl))
199438fd1498Szrj 	locate_old_decl (olddecl);
199538fd1498Szrj 
199638fd1498Szrj       return true;
199738fd1498Szrj     }
199838fd1498Szrj 
199938fd1498Szrj   /* Function declarations can either be 'static' or 'extern' (no
200038fd1498Szrj      qualifier is equivalent to 'extern' - C99 6.2.2p5) and therefore
200138fd1498Szrj      can never conflict with each other on account of linkage
200238fd1498Szrj      (6.2.2p4).  Multiple definitions are not allowed (6.9p3,5) but
200338fd1498Szrj      gnu89 mode permits two definitions if one is 'extern inline' and
200438fd1498Szrj      one is not.  The non- extern-inline definition supersedes the
200538fd1498Szrj      extern-inline definition.  */
200638fd1498Szrj 
200738fd1498Szrj   else if (TREE_CODE (newdecl) == FUNCTION_DECL)
200838fd1498Szrj     {
200938fd1498Szrj       /* If you declare a built-in function name as static, or
201038fd1498Szrj 	 define the built-in with an old-style definition (so we
201138fd1498Szrj 	 can't validate the argument list) the built-in definition is
201238fd1498Szrj 	 overridden, but optionally warn this was a bad choice of name.  */
201338fd1498Szrj       if (DECL_BUILT_IN (olddecl)
201438fd1498Szrj 	  && !C_DECL_DECLARED_BUILTIN (olddecl)
201538fd1498Szrj 	  && (!TREE_PUBLIC (newdecl)
201638fd1498Szrj 	      || (DECL_INITIAL (newdecl)
201738fd1498Szrj 		  && !prototype_p (TREE_TYPE (newdecl)))))
201838fd1498Szrj 	{
201938fd1498Szrj 	  warning (OPT_Wshadow, "declaration of %q+D shadows "
202038fd1498Szrj 		   "a built-in function", newdecl);
202138fd1498Szrj 	  /* Discard the old built-in function.  */
202238fd1498Szrj 	  return false;
202338fd1498Szrj 	}
202438fd1498Szrj 
202538fd1498Szrj       if (DECL_INITIAL (newdecl))
202638fd1498Szrj 	{
202738fd1498Szrj 	  if (DECL_INITIAL (olddecl))
202838fd1498Szrj 	    {
202938fd1498Szrj 	      /* If both decls are in the same TU and the new declaration
203038fd1498Szrj 		 isn't overriding an extern inline reject the new decl.
203138fd1498Szrj 		 In c99, no overriding is allowed in the same translation
203238fd1498Szrj 		 unit.  */
203338fd1498Szrj 	      if ((!DECL_EXTERN_INLINE (olddecl)
203438fd1498Szrj 		   || DECL_EXTERN_INLINE (newdecl)
203538fd1498Szrj 		   || (!flag_gnu89_inline
203638fd1498Szrj 		       && (!DECL_DECLARED_INLINE_P (olddecl)
203738fd1498Szrj 			   || !lookup_attribute ("gnu_inline",
203838fd1498Szrj 						 DECL_ATTRIBUTES (olddecl)))
203938fd1498Szrj 		       && (!DECL_DECLARED_INLINE_P (newdecl)
204038fd1498Szrj 			   || !lookup_attribute ("gnu_inline",
204138fd1498Szrj 						 DECL_ATTRIBUTES (newdecl))))
204238fd1498Szrj 		  )
204338fd1498Szrj 		  && same_translation_unit_p (newdecl, olddecl))
204438fd1498Szrj 		{
204538fd1498Szrj 		  error ("redefinition of %q+D", newdecl);
204638fd1498Szrj 		  locate_old_decl (olddecl);
204738fd1498Szrj 		  return false;
204838fd1498Szrj 		}
204938fd1498Szrj 	    }
205038fd1498Szrj 	}
205138fd1498Szrj       /* If we have a prototype after an old-style function definition,
205238fd1498Szrj 	 the argument types must be checked specially.  */
205338fd1498Szrj       else if (DECL_INITIAL (olddecl)
205438fd1498Szrj 	       && !prototype_p (oldtype) && prototype_p (newtype)
205538fd1498Szrj 	       && TYPE_ACTUAL_ARG_TYPES (oldtype)
205638fd1498Szrj 	       && !validate_proto_after_old_defn (newdecl, newtype, oldtype))
205738fd1498Szrj 	{
205838fd1498Szrj 	  locate_old_decl (olddecl);
205938fd1498Szrj 	  return false;
206038fd1498Szrj 	}
206138fd1498Szrj       /* A non-static declaration (even an "extern") followed by a
206238fd1498Szrj 	 static declaration is undefined behavior per C99 6.2.2p3-5,7.
206338fd1498Szrj 	 The same is true for a static forward declaration at block
206438fd1498Szrj 	 scope followed by a non-static declaration/definition at file
206538fd1498Szrj 	 scope.  Static followed by non-static at the same scope is
206638fd1498Szrj 	 not undefined behavior, and is the most convenient way to get
206738fd1498Szrj 	 some effects (see e.g.  what unwind-dw2-fde-glibc.c does to
206838fd1498Szrj 	 the definition of _Unwind_Find_FDE in unwind-dw2-fde.c), but
206938fd1498Szrj 	 we do diagnose it if -Wtraditional.  */
207038fd1498Szrj       if (TREE_PUBLIC (olddecl) && !TREE_PUBLIC (newdecl))
207138fd1498Szrj 	{
207238fd1498Szrj 	  /* Two exceptions to the rule.  If olddecl is an extern
207338fd1498Szrj 	     inline, or a predeclared function that isn't actually
207438fd1498Szrj 	     built in, newdecl silently overrides olddecl.  The latter
207538fd1498Szrj 	     occur only in Objective C; see also above.  (FIXME: Make
207638fd1498Szrj 	     Objective C use normal builtins.)  */
207738fd1498Szrj 	  if (!DECL_IS_BUILTIN (olddecl)
207838fd1498Szrj 	      && !DECL_EXTERN_INLINE (olddecl))
207938fd1498Szrj 	    {
208038fd1498Szrj 	      error ("static declaration of %q+D follows "
208138fd1498Szrj 		     "non-static declaration", newdecl);
208238fd1498Szrj 	      locate_old_decl (olddecl);
208338fd1498Szrj 	    }
208438fd1498Szrj 	  return false;
208538fd1498Szrj 	}
208638fd1498Szrj       else if (TREE_PUBLIC (newdecl) && !TREE_PUBLIC (olddecl))
208738fd1498Szrj 	{
208838fd1498Szrj 	  if (DECL_CONTEXT (olddecl))
208938fd1498Szrj 	    {
209038fd1498Szrj 	      error ("non-static declaration of %q+D follows "
209138fd1498Szrj 		     "static declaration", newdecl);
209238fd1498Szrj 	      locate_old_decl (olddecl);
209338fd1498Szrj 	      return false;
209438fd1498Szrj 	    }
209538fd1498Szrj 	  else if (warn_traditional)
209638fd1498Szrj 	    {
209738fd1498Szrj 	      warned |= warning (OPT_Wtraditional,
209838fd1498Szrj 				 "non-static declaration of %q+D "
209938fd1498Szrj 				 "follows static declaration", newdecl);
210038fd1498Szrj 	    }
210138fd1498Szrj 	}
210238fd1498Szrj 
210338fd1498Szrj       /* Make sure gnu_inline attribute is either not present, or
210438fd1498Szrj 	 present on all inline decls.  */
210538fd1498Szrj       if (DECL_DECLARED_INLINE_P (olddecl)
210638fd1498Szrj 	  && DECL_DECLARED_INLINE_P (newdecl))
210738fd1498Szrj 	{
210838fd1498Szrj 	  bool newa = lookup_attribute ("gnu_inline",
210938fd1498Szrj 					DECL_ATTRIBUTES (newdecl)) != NULL;
211038fd1498Szrj 	  bool olda = lookup_attribute ("gnu_inline",
211138fd1498Szrj 					DECL_ATTRIBUTES (olddecl)) != NULL;
211238fd1498Szrj 	  if (newa != olda)
211338fd1498Szrj 	    {
211438fd1498Szrj 	      error_at (input_location, "%<gnu_inline%> attribute present on %q+D",
211538fd1498Szrj 			newa ? newdecl : olddecl);
211638fd1498Szrj 	      error_at (DECL_SOURCE_LOCATION (newa ? olddecl : newdecl),
211738fd1498Szrj 			"but not here");
211838fd1498Szrj 	    }
211938fd1498Szrj 	}
212038fd1498Szrj     }
212138fd1498Szrj   else if (VAR_P (newdecl))
212238fd1498Szrj     {
212338fd1498Szrj       /* Only variables can be thread-local, and all declarations must
212438fd1498Szrj 	 agree on this property.  */
212538fd1498Szrj       if (C_DECL_THREADPRIVATE_P (olddecl) && !DECL_THREAD_LOCAL_P (newdecl))
212638fd1498Szrj 	{
212738fd1498Szrj 	  /* Nothing to check.  Since OLDDECL is marked threadprivate
212838fd1498Szrj 	     and NEWDECL does not have a thread-local attribute, we
212938fd1498Szrj 	     will merge the threadprivate attribute into NEWDECL.  */
213038fd1498Szrj 	  ;
213138fd1498Szrj 	}
213238fd1498Szrj       else if (DECL_THREAD_LOCAL_P (newdecl) != DECL_THREAD_LOCAL_P (olddecl))
213338fd1498Szrj 	{
213438fd1498Szrj 	  if (DECL_THREAD_LOCAL_P (newdecl))
213538fd1498Szrj 	    error ("thread-local declaration of %q+D follows "
213638fd1498Szrj 		   "non-thread-local declaration", newdecl);
213738fd1498Szrj 	  else
213838fd1498Szrj 	    error ("non-thread-local declaration of %q+D follows "
213938fd1498Szrj 		   "thread-local declaration", newdecl);
214038fd1498Szrj 
214138fd1498Szrj 	  locate_old_decl (olddecl);
214238fd1498Szrj 	  return false;
214338fd1498Szrj 	}
214438fd1498Szrj 
214538fd1498Szrj       /* Multiple initialized definitions are not allowed (6.9p3,5).  */
214638fd1498Szrj       if (DECL_INITIAL (newdecl) && DECL_INITIAL (olddecl))
214738fd1498Szrj 	{
214838fd1498Szrj 	  error ("redefinition of %q+D", newdecl);
214938fd1498Szrj 	  locate_old_decl (olddecl);
215038fd1498Szrj 	  return false;
215138fd1498Szrj 	}
215238fd1498Szrj 
215338fd1498Szrj       /* Objects declared at file scope: if the first declaration had
215438fd1498Szrj 	 external linkage (even if it was an external reference) the
215538fd1498Szrj 	 second must have external linkage as well, or the behavior is
215638fd1498Szrj 	 undefined.  If the first declaration had internal linkage, then
215738fd1498Szrj 	 the second must too, or else be an external reference (in which
215838fd1498Szrj 	 case the composite declaration still has internal linkage).
215938fd1498Szrj 	 As for function declarations, we warn about the static-then-
216038fd1498Szrj 	 extern case only for -Wtraditional.  See generally 6.2.2p3-5,7.  */
216138fd1498Szrj       if (DECL_FILE_SCOPE_P (newdecl)
216238fd1498Szrj 	  && TREE_PUBLIC (newdecl) != TREE_PUBLIC (olddecl))
216338fd1498Szrj 	{
216438fd1498Szrj 	  if (DECL_EXTERNAL (newdecl))
216538fd1498Szrj 	    {
216638fd1498Szrj 	      if (!DECL_FILE_SCOPE_P (olddecl))
216738fd1498Szrj 		{
216838fd1498Szrj 		  error ("extern declaration of %q+D follows "
216938fd1498Szrj 			 "declaration with no linkage", newdecl);
217038fd1498Szrj 		  locate_old_decl (olddecl);
217138fd1498Szrj 		  return false;
217238fd1498Szrj 		}
217338fd1498Szrj 	      else if (warn_traditional)
217438fd1498Szrj 		{
217538fd1498Szrj 		  warned |= warning (OPT_Wtraditional,
217638fd1498Szrj 				     "non-static declaration of %q+D "
217738fd1498Szrj 				     "follows static declaration", newdecl);
217838fd1498Szrj 		}
217938fd1498Szrj 	    }
218038fd1498Szrj 	  else
218138fd1498Szrj 	    {
218238fd1498Szrj 	      if (TREE_PUBLIC (newdecl))
218338fd1498Szrj 		error ("non-static declaration of %q+D follows "
218438fd1498Szrj 		       "static declaration", newdecl);
218538fd1498Szrj 	      else
218638fd1498Szrj 		error ("static declaration of %q+D follows "
218738fd1498Szrj 		       "non-static declaration", newdecl);
218838fd1498Szrj 
218938fd1498Szrj 	      locate_old_decl (olddecl);
219038fd1498Szrj 	      return false;
219138fd1498Szrj 	    }
219238fd1498Szrj 	}
219338fd1498Szrj       /* Two objects with the same name declared at the same block
219438fd1498Szrj 	 scope must both be external references (6.7p3).  */
219538fd1498Szrj       else if (!DECL_FILE_SCOPE_P (newdecl))
219638fd1498Szrj 	{
219738fd1498Szrj 	  if (DECL_EXTERNAL (newdecl))
219838fd1498Szrj 	    {
219938fd1498Szrj 	      /* Extern with initializer at block scope, which will
220038fd1498Szrj 		 already have received an error.  */
220138fd1498Szrj 	    }
220238fd1498Szrj 	  else if (DECL_EXTERNAL (olddecl))
220338fd1498Szrj 	    {
220438fd1498Szrj 	      error ("declaration of %q+D with no linkage follows "
220538fd1498Szrj 		     "extern declaration", newdecl);
220638fd1498Szrj 	      locate_old_decl (olddecl);
220738fd1498Szrj 	    }
220838fd1498Szrj 	  else
220938fd1498Szrj 	    {
221038fd1498Szrj 	      error ("redeclaration of %q+D with no linkage", newdecl);
221138fd1498Szrj 	      locate_old_decl (olddecl);
221238fd1498Szrj 	    }
221338fd1498Szrj 
221438fd1498Szrj 	  return false;
221538fd1498Szrj 	}
221638fd1498Szrj 
221738fd1498Szrj       /* C++ does not permit a decl to appear multiple times at file
221838fd1498Szrj 	 scope.  */
221938fd1498Szrj       if (warn_cxx_compat
222038fd1498Szrj 	  && DECL_FILE_SCOPE_P (newdecl)
222138fd1498Szrj 	  && !DECL_EXTERNAL (newdecl)
222238fd1498Szrj 	  && !DECL_EXTERNAL (olddecl))
222338fd1498Szrj 	warned |= warning_at (DECL_SOURCE_LOCATION (newdecl),
222438fd1498Szrj 			      OPT_Wc___compat,
222538fd1498Szrj 			      ("duplicate declaration of %qD is "
222638fd1498Szrj 			       "invalid in C++"),
222738fd1498Szrj 			      newdecl);
222838fd1498Szrj     }
222938fd1498Szrj 
223038fd1498Szrj   /* warnings */
223138fd1498Szrj   /* All decls must agree on a visibility.  */
223238fd1498Szrj   if (CODE_CONTAINS_STRUCT (TREE_CODE (newdecl), TS_DECL_WITH_VIS)
223338fd1498Szrj       && DECL_VISIBILITY_SPECIFIED (newdecl) && DECL_VISIBILITY_SPECIFIED (olddecl)
223438fd1498Szrj       && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
223538fd1498Szrj     {
223638fd1498Szrj       warned |= warning (0, "redeclaration of %q+D with different visibility "
223738fd1498Szrj 			 "(old visibility preserved)", newdecl);
223838fd1498Szrj     }
223938fd1498Szrj 
224038fd1498Szrj   if (TREE_CODE (newdecl) == FUNCTION_DECL)
224138fd1498Szrj     warned |= diagnose_mismatched_attributes (olddecl, newdecl);
224238fd1498Szrj   else /* PARM_DECL, VAR_DECL */
224338fd1498Szrj     {
224438fd1498Szrj       /* Redeclaration of a parameter is a constraint violation (this is
224538fd1498Szrj 	 not explicitly stated, but follows from C99 6.7p3 [no more than
224638fd1498Szrj 	 one declaration of the same identifier with no linkage in the
224738fd1498Szrj 	 same scope, except type tags] and 6.2.2p6 [parameters have no
224838fd1498Szrj 	 linkage]).  We must check for a forward parameter declaration,
224938fd1498Szrj 	 indicated by TREE_ASM_WRITTEN on the old declaration - this is
225038fd1498Szrj 	 an extension, the mandatory diagnostic for which is handled by
225138fd1498Szrj 	 mark_forward_parm_decls.  */
225238fd1498Szrj 
225338fd1498Szrj       if (TREE_CODE (newdecl) == PARM_DECL
225438fd1498Szrj 	  && (!TREE_ASM_WRITTEN (olddecl) || TREE_ASM_WRITTEN (newdecl)))
225538fd1498Szrj 	{
225638fd1498Szrj 	  error ("redefinition of parameter %q+D", newdecl);
225738fd1498Szrj 	  locate_old_decl (olddecl);
225838fd1498Szrj 	  return false;
225938fd1498Szrj 	}
226038fd1498Szrj     }
226138fd1498Szrj 
226238fd1498Szrj   /* Optional warning for completely redundant decls.  */
226338fd1498Szrj   if (!warned && !pedwarned
226438fd1498Szrj       && warn_redundant_decls
226538fd1498Szrj       /* Don't warn about a function declaration followed by a
226638fd1498Szrj 	 definition.  */
226738fd1498Szrj       && !(TREE_CODE (newdecl) == FUNCTION_DECL
226838fd1498Szrj 	   && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl))
226938fd1498Szrj       /* Don't warn about redundant redeclarations of builtins.  */
227038fd1498Szrj       && !(TREE_CODE (newdecl) == FUNCTION_DECL
227138fd1498Szrj 	   && !DECL_BUILT_IN (newdecl)
227238fd1498Szrj 	   && DECL_BUILT_IN (olddecl)
227338fd1498Szrj 	   && !C_DECL_DECLARED_BUILTIN (olddecl))
227438fd1498Szrj       /* Don't warn about an extern followed by a definition.  */
227538fd1498Szrj       && !(DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl))
227638fd1498Szrj       /* Don't warn about forward parameter decls.  */
227738fd1498Szrj       && !(TREE_CODE (newdecl) == PARM_DECL
227838fd1498Szrj 	   && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
227938fd1498Szrj       /* Don't warn about a variable definition following a declaration.  */
228038fd1498Szrj       && !(VAR_P (newdecl)
228138fd1498Szrj 	   && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl)))
228238fd1498Szrj     {
228338fd1498Szrj       warned = warning (OPT_Wredundant_decls, "redundant redeclaration of %q+D",
228438fd1498Szrj 			newdecl);
228538fd1498Szrj     }
228638fd1498Szrj 
228738fd1498Szrj   /* Report location of previous decl/defn.  */
228838fd1498Szrj   if (warned || pedwarned)
228938fd1498Szrj     locate_old_decl (olddecl);
229038fd1498Szrj 
229138fd1498Szrj #undef DECL_EXTERN_INLINE
229238fd1498Szrj 
229338fd1498Szrj   return retval;
229438fd1498Szrj }
229538fd1498Szrj 
229638fd1498Szrj /* Subroutine of duplicate_decls.  NEWDECL has been found to be
229738fd1498Szrj    consistent with OLDDECL, but carries new information.  Merge the
229838fd1498Szrj    new information into OLDDECL.  This function issues no
229938fd1498Szrj    diagnostics.  */
230038fd1498Szrj 
230138fd1498Szrj static void
merge_decls(tree newdecl,tree olddecl,tree newtype,tree oldtype)230238fd1498Szrj merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
230338fd1498Szrj {
230438fd1498Szrj   bool new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL
230538fd1498Szrj 			    && DECL_INITIAL (newdecl) != NULL_TREE);
230638fd1498Szrj   bool new_is_prototype = (TREE_CODE (newdecl) == FUNCTION_DECL
230738fd1498Szrj 			   && prototype_p (TREE_TYPE (newdecl)));
230838fd1498Szrj   bool old_is_prototype = (TREE_CODE (olddecl) == FUNCTION_DECL
230938fd1498Szrj 			   && prototype_p (TREE_TYPE (olddecl)));
231038fd1498Szrj 
231138fd1498Szrj   /* For real parm decl following a forward decl, rechain the old decl
231238fd1498Szrj      in its new location and clear TREE_ASM_WRITTEN (it's not a
231338fd1498Szrj      forward decl anymore).  */
231438fd1498Szrj   if (TREE_CODE (newdecl) == PARM_DECL
231538fd1498Szrj       && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
231638fd1498Szrj     {
231738fd1498Szrj       struct c_binding *b, **here;
231838fd1498Szrj 
231938fd1498Szrj       for (here = &current_scope->bindings; *here; here = &(*here)->prev)
232038fd1498Szrj 	if ((*here)->decl == olddecl)
232138fd1498Szrj 	  goto found;
232238fd1498Szrj       gcc_unreachable ();
232338fd1498Szrj 
232438fd1498Szrj     found:
232538fd1498Szrj       b = *here;
232638fd1498Szrj       *here = b->prev;
232738fd1498Szrj       b->prev = current_scope->bindings;
232838fd1498Szrj       current_scope->bindings = b;
232938fd1498Szrj 
233038fd1498Szrj       TREE_ASM_WRITTEN (olddecl) = 0;
233138fd1498Szrj     }
233238fd1498Szrj 
233338fd1498Szrj   DECL_ATTRIBUTES (newdecl)
233438fd1498Szrj     = targetm.merge_decl_attributes (olddecl, newdecl);
233538fd1498Szrj 
233638fd1498Szrj   /* For typedefs use the old type, as the new type's DECL_NAME points
233738fd1498Szrj      at newdecl, which will be ggc_freed.  */
233838fd1498Szrj   if (TREE_CODE (newdecl) == TYPE_DECL)
233938fd1498Szrj     {
234038fd1498Szrj       /* But NEWTYPE might have an attribute, honor that.  */
234138fd1498Szrj       tree tem = newtype;
234238fd1498Szrj       newtype = oldtype;
234338fd1498Szrj 
234438fd1498Szrj       if (TYPE_USER_ALIGN (tem))
234538fd1498Szrj 	{
234638fd1498Szrj 	  if (TYPE_ALIGN (tem) > TYPE_ALIGN (newtype))
234738fd1498Szrj 	    SET_TYPE_ALIGN (newtype, TYPE_ALIGN (tem));
234838fd1498Szrj 	  TYPE_USER_ALIGN (newtype) = true;
234938fd1498Szrj 	}
235038fd1498Szrj 
235138fd1498Szrj       /* And remove the new type from the variants list.  */
235238fd1498Szrj       if (TYPE_NAME (TREE_TYPE (newdecl)) == newdecl)
235338fd1498Szrj 	{
235438fd1498Szrj 	  tree remove = TREE_TYPE (newdecl);
235538fd1498Szrj 	  for (tree t = TYPE_MAIN_VARIANT (remove); ;
235638fd1498Szrj 	       t = TYPE_NEXT_VARIANT (t))
235738fd1498Szrj 	    if (TYPE_NEXT_VARIANT (t) == remove)
235838fd1498Szrj 	      {
235938fd1498Szrj 		TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (remove);
236038fd1498Szrj 		break;
236138fd1498Szrj 	      }
236238fd1498Szrj 	}
236338fd1498Szrj     }
236438fd1498Szrj 
236538fd1498Szrj   /* Merge the data types specified in the two decls.  */
236638fd1498Szrj   TREE_TYPE (newdecl)
236738fd1498Szrj     = TREE_TYPE (olddecl)
236838fd1498Szrj     = composite_type (newtype, oldtype);
236938fd1498Szrj 
237038fd1498Szrj   /* Lay the type out, unless already done.  */
237138fd1498Szrj   if (!comptypes (oldtype, TREE_TYPE (newdecl)))
237238fd1498Szrj     {
237338fd1498Szrj       if (TREE_TYPE (newdecl) != error_mark_node)
237438fd1498Szrj 	layout_type (TREE_TYPE (newdecl));
237538fd1498Szrj       if (TREE_CODE (newdecl) != FUNCTION_DECL
237638fd1498Szrj 	  && TREE_CODE (newdecl) != TYPE_DECL
237738fd1498Szrj 	  && TREE_CODE (newdecl) != CONST_DECL)
237838fd1498Szrj 	layout_decl (newdecl, 0);
237938fd1498Szrj     }
238038fd1498Szrj   else
238138fd1498Szrj     {
238238fd1498Szrj       /* Since the type is OLDDECL's, make OLDDECL's size go with.  */
238338fd1498Szrj       DECL_SIZE (newdecl) = DECL_SIZE (olddecl);
238438fd1498Szrj       DECL_SIZE_UNIT (newdecl) = DECL_SIZE_UNIT (olddecl);
238538fd1498Szrj       SET_DECL_MODE (newdecl, DECL_MODE (olddecl));
238638fd1498Szrj       if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
238738fd1498Szrj 	{
238838fd1498Szrj 	  SET_DECL_ALIGN (newdecl, DECL_ALIGN (olddecl));
238938fd1498Szrj 	  DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl);
239038fd1498Szrj 	}
239138fd1498Szrj       if (DECL_WARN_IF_NOT_ALIGN (olddecl)
239238fd1498Szrj 	  > DECL_WARN_IF_NOT_ALIGN (newdecl))
239338fd1498Szrj 	SET_DECL_WARN_IF_NOT_ALIGN (newdecl,
239438fd1498Szrj 				    DECL_WARN_IF_NOT_ALIGN (olddecl));
239538fd1498Szrj     }
239638fd1498Szrj 
239738fd1498Szrj   /* Keep the old rtl since we can safely use it.  */
239838fd1498Szrj   if (HAS_RTL_P (olddecl))
239938fd1498Szrj     COPY_DECL_RTL (olddecl, newdecl);
240038fd1498Szrj 
240138fd1498Szrj   /* Merge the type qualifiers.  */
240238fd1498Szrj   if (TREE_READONLY (newdecl))
240338fd1498Szrj     TREE_READONLY (olddecl) = 1;
240438fd1498Szrj 
240538fd1498Szrj   if (TREE_THIS_VOLATILE (newdecl))
240638fd1498Szrj     TREE_THIS_VOLATILE (olddecl) = 1;
240738fd1498Szrj 
240838fd1498Szrj   /* Merge deprecatedness.  */
240938fd1498Szrj   if (TREE_DEPRECATED (newdecl))
241038fd1498Szrj     TREE_DEPRECATED (olddecl) = 1;
241138fd1498Szrj 
241238fd1498Szrj   /* If a decl is in a system header and the other isn't, keep the one on the
241338fd1498Szrj      system header. Otherwise, keep source location of definition rather than
241438fd1498Szrj      declaration and of prototype rather than non-prototype unless that
241538fd1498Szrj      prototype is built-in.  */
241638fd1498Szrj   if (CODE_CONTAINS_STRUCT (TREE_CODE (olddecl), TS_DECL_WITH_VIS)
241738fd1498Szrj       && DECL_IN_SYSTEM_HEADER (olddecl)
241838fd1498Szrj       && !DECL_IN_SYSTEM_HEADER (newdecl) )
241938fd1498Szrj     DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
242038fd1498Szrj   else if (CODE_CONTAINS_STRUCT (TREE_CODE (olddecl), TS_DECL_WITH_VIS)
242138fd1498Szrj 	   && DECL_IN_SYSTEM_HEADER (newdecl)
242238fd1498Szrj 	   && !DECL_IN_SYSTEM_HEADER (olddecl))
242338fd1498Szrj     DECL_SOURCE_LOCATION (olddecl) = DECL_SOURCE_LOCATION (newdecl);
242438fd1498Szrj   else if ((DECL_INITIAL (newdecl) == NULL_TREE
242538fd1498Szrj 	    && DECL_INITIAL (olddecl) != NULL_TREE)
242638fd1498Szrj 	   || (old_is_prototype && !new_is_prototype
242738fd1498Szrj 	       && !C_DECL_BUILTIN_PROTOTYPE (olddecl)))
242838fd1498Szrj     DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
242938fd1498Szrj 
243038fd1498Szrj   /* Merge the initialization information.  */
243138fd1498Szrj    if (DECL_INITIAL (newdecl) == NULL_TREE)
243238fd1498Szrj     DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
243338fd1498Szrj 
243438fd1498Szrj   /* Merge the threadprivate attribute.  */
243538fd1498Szrj   if (VAR_P (olddecl) && C_DECL_THREADPRIVATE_P (olddecl))
243638fd1498Szrj     C_DECL_THREADPRIVATE_P (newdecl) = 1;
243738fd1498Szrj 
243838fd1498Szrj   if (CODE_CONTAINS_STRUCT (TREE_CODE (olddecl), TS_DECL_WITH_VIS))
243938fd1498Szrj     {
244038fd1498Szrj       /* Copy the assembler name.
244138fd1498Szrj 	 Currently, it can only be defined in the prototype.  */
244238fd1498Szrj       COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
244338fd1498Szrj 
244438fd1498Szrj       /* Use visibility of whichever declaration had it specified */
244538fd1498Szrj       if (DECL_VISIBILITY_SPECIFIED (olddecl))
244638fd1498Szrj 	{
244738fd1498Szrj 	  DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
244838fd1498Szrj 	  DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
244938fd1498Szrj 	}
245038fd1498Szrj 
245138fd1498Szrj       if (TREE_CODE (newdecl) == FUNCTION_DECL)
245238fd1498Szrj 	{
245338fd1498Szrj 	  DECL_STATIC_CONSTRUCTOR(newdecl) |= DECL_STATIC_CONSTRUCTOR(olddecl);
245438fd1498Szrj 	  DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
245538fd1498Szrj 	  DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
245638fd1498Szrj 	  DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
245738fd1498Szrj 	    |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
245838fd1498Szrj 	  TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
245938fd1498Szrj 	  DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
246038fd1498Szrj 	  DECL_IS_OPERATOR_NEW (newdecl) |= DECL_IS_OPERATOR_NEW (olddecl);
246138fd1498Szrj 	  TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
246238fd1498Szrj 	  DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl);
246338fd1498Szrj 	  DECL_IS_NOVOPS (newdecl) |= DECL_IS_NOVOPS (olddecl);
246438fd1498Szrj 	}
246538fd1498Szrj 
246638fd1498Szrj       /* Merge the storage class information.  */
246738fd1498Szrj       merge_weak (newdecl, olddecl);
246838fd1498Szrj 
246938fd1498Szrj       /* For functions, static overrides non-static.  */
247038fd1498Szrj       if (TREE_CODE (newdecl) == FUNCTION_DECL)
247138fd1498Szrj 	{
247238fd1498Szrj 	  TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl);
247338fd1498Szrj 	  /* This is since we don't automatically
247438fd1498Szrj 	     copy the attributes of NEWDECL into OLDDECL.  */
247538fd1498Szrj 	  TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
247638fd1498Szrj 	  /* If this clears `static', clear it in the identifier too.  */
247738fd1498Szrj 	  if (!TREE_PUBLIC (olddecl))
247838fd1498Szrj 	    TREE_PUBLIC (DECL_NAME (olddecl)) = 0;
247938fd1498Szrj 	}
248038fd1498Szrj     }
248138fd1498Szrj 
248238fd1498Szrj   /* In c99, 'extern' declaration before (or after) 'inline' means this
248338fd1498Szrj      function is not DECL_EXTERNAL, unless 'gnu_inline' attribute
248438fd1498Szrj      is present.  */
248538fd1498Szrj   if (TREE_CODE (newdecl) == FUNCTION_DECL
248638fd1498Szrj       && !flag_gnu89_inline
248738fd1498Szrj       && (DECL_DECLARED_INLINE_P (newdecl)
248838fd1498Szrj 	  || DECL_DECLARED_INLINE_P (olddecl))
248938fd1498Szrj       && (!DECL_DECLARED_INLINE_P (newdecl)
249038fd1498Szrj 	  || !DECL_DECLARED_INLINE_P (olddecl)
249138fd1498Szrj 	  || !DECL_EXTERNAL (olddecl))
249238fd1498Szrj       && DECL_EXTERNAL (newdecl)
249338fd1498Szrj       && !lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (newdecl))
249438fd1498Szrj       && !current_function_decl)
249538fd1498Szrj     DECL_EXTERNAL (newdecl) = 0;
249638fd1498Szrj 
249738fd1498Szrj   /* An inline definition following a static declaration is not
249838fd1498Szrj      DECL_EXTERNAL.  */
249938fd1498Szrj   if (new_is_definition
250038fd1498Szrj       && (DECL_DECLARED_INLINE_P (newdecl)
250138fd1498Szrj 	  || DECL_DECLARED_INLINE_P (olddecl))
250238fd1498Szrj       && !TREE_PUBLIC (olddecl))
250338fd1498Szrj     DECL_EXTERNAL (newdecl) = 0;
250438fd1498Szrj 
250538fd1498Szrj   if (DECL_EXTERNAL (newdecl))
250638fd1498Szrj     {
250738fd1498Szrj       TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
250838fd1498Szrj       DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl);
250938fd1498Szrj 
251038fd1498Szrj       /* An extern decl does not override previous storage class.  */
251138fd1498Szrj       TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
251238fd1498Szrj       if (!DECL_EXTERNAL (newdecl))
251338fd1498Szrj 	{
251438fd1498Szrj 	  DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
251538fd1498Szrj 	  DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
251638fd1498Szrj 	}
251738fd1498Szrj     }
251838fd1498Szrj   else
251938fd1498Szrj     {
252038fd1498Szrj       TREE_STATIC (olddecl) = TREE_STATIC (newdecl);
252138fd1498Szrj       TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
252238fd1498Szrj     }
252338fd1498Szrj 
252438fd1498Szrj   if (TREE_CODE (newdecl) == FUNCTION_DECL)
252538fd1498Szrj     {
252638fd1498Szrj       /* If we're redefining a function previously defined as extern
252738fd1498Szrj 	 inline, make sure we emit debug info for the inline before we
252838fd1498Szrj 	 throw it away, in case it was inlined into a function that
252938fd1498Szrj 	 hasn't been written out yet.  */
253038fd1498Szrj       if (new_is_definition && DECL_INITIAL (olddecl))
253138fd1498Szrj 	/* The new defn must not be inline.  */
253238fd1498Szrj 	DECL_UNINLINABLE (newdecl) = 1;
253338fd1498Szrj       else
253438fd1498Szrj 	{
253538fd1498Szrj 	  /* If either decl says `inline', this fn is inline, unless
253638fd1498Szrj 	     its definition was passed already.  */
253738fd1498Szrj 	  if (DECL_DECLARED_INLINE_P (newdecl)
253838fd1498Szrj 	      || DECL_DECLARED_INLINE_P (olddecl))
253938fd1498Szrj 	    DECL_DECLARED_INLINE_P (newdecl) = 1;
254038fd1498Szrj 
254138fd1498Szrj 	  DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
254238fd1498Szrj 	    = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
254338fd1498Szrj 
254438fd1498Szrj 	  DECL_DISREGARD_INLINE_LIMITS (newdecl)
254538fd1498Szrj 	    = DECL_DISREGARD_INLINE_LIMITS (olddecl)
254638fd1498Szrj 	    = (DECL_DISREGARD_INLINE_LIMITS (newdecl)
254738fd1498Szrj 	       || DECL_DISREGARD_INLINE_LIMITS (olddecl));
254838fd1498Szrj 	}
254938fd1498Szrj 
255038fd1498Szrj       if (DECL_BUILT_IN (olddecl))
255138fd1498Szrj 	{
255238fd1498Szrj 	  /* If redeclaring a builtin function, it stays built in.
255338fd1498Szrj 	     But it gets tagged as having been declared.  */
255438fd1498Szrj 	  DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl);
255538fd1498Szrj 	  DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
255638fd1498Szrj 	  C_DECL_DECLARED_BUILTIN (newdecl) = 1;
255738fd1498Szrj 	  if (new_is_prototype)
255838fd1498Szrj 	    {
255938fd1498Szrj 	      C_DECL_BUILTIN_PROTOTYPE (newdecl) = 0;
256038fd1498Szrj 	      if (DECL_BUILT_IN_CLASS (newdecl) == BUILT_IN_NORMAL)
256138fd1498Szrj 		{
256238fd1498Szrj 		  enum built_in_function fncode = DECL_FUNCTION_CODE (newdecl);
256338fd1498Szrj 		  switch (fncode)
256438fd1498Szrj 		    {
256538fd1498Szrj 		      /* If a compatible prototype of these builtin functions
256638fd1498Szrj 			 is seen, assume the runtime implements it with the
256738fd1498Szrj 			 expected semantics.  */
256838fd1498Szrj 		    case BUILT_IN_STPCPY:
256938fd1498Szrj 		      if (builtin_decl_explicit_p (fncode))
257038fd1498Szrj 			set_builtin_decl_implicit_p (fncode, true);
257138fd1498Szrj 		      break;
257238fd1498Szrj 		    default:
257338fd1498Szrj 		      if (builtin_decl_explicit_p (fncode))
257438fd1498Szrj 			set_builtin_decl_declared_p (fncode, true);
257538fd1498Szrj 		      break;
257638fd1498Szrj 		    }
257738fd1498Szrj 
257838fd1498Szrj 		  copy_attributes_to_builtin (newdecl);
257938fd1498Szrj 		}
258038fd1498Szrj 	    }
258138fd1498Szrj 	  else
258238fd1498Szrj 	    C_DECL_BUILTIN_PROTOTYPE (newdecl)
258338fd1498Szrj 	      = C_DECL_BUILTIN_PROTOTYPE (olddecl);
258438fd1498Szrj 	}
258538fd1498Szrj 
258638fd1498Szrj       /* Preserve function specific target and optimization options */
258738fd1498Szrj       if (DECL_FUNCTION_SPECIFIC_TARGET (olddecl)
258838fd1498Szrj 	  && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl))
258938fd1498Szrj 	DECL_FUNCTION_SPECIFIC_TARGET (newdecl)
259038fd1498Szrj 	  = DECL_FUNCTION_SPECIFIC_TARGET (olddecl);
259138fd1498Szrj 
259238fd1498Szrj       if (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl)
259338fd1498Szrj 	  && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl))
259438fd1498Szrj 	DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)
259538fd1498Szrj 	  = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl);
259638fd1498Szrj 
259738fd1498Szrj       /* Also preserve various other info from the definition.  */
259838fd1498Szrj       if (!new_is_definition)
259938fd1498Szrj 	{
260038fd1498Szrj 	  tree t;
260138fd1498Szrj 	  DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
260238fd1498Szrj 	  DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
260338fd1498Szrj 	  DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
260438fd1498Szrj 	  DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
260538fd1498Szrj 	  DECL_ARGUMENTS (newdecl) = copy_list (DECL_ARGUMENTS (olddecl));
260638fd1498Szrj 	  for (t = DECL_ARGUMENTS (newdecl); t ; t = DECL_CHAIN (t))
260738fd1498Szrj 	    DECL_CONTEXT (t) = newdecl;
260838fd1498Szrj 
260938fd1498Szrj 	  /* See if we've got a function to instantiate from.  */
261038fd1498Szrj 	  if (DECL_SAVED_TREE (olddecl))
261138fd1498Szrj 	    DECL_ABSTRACT_ORIGIN (newdecl)
261238fd1498Szrj 	      = DECL_ABSTRACT_ORIGIN (olddecl);
261338fd1498Szrj 	}
261438fd1498Szrj     }
261538fd1498Szrj 
261638fd1498Szrj   /* Merge the USED information.  */
261738fd1498Szrj   if (TREE_USED (olddecl))
261838fd1498Szrj     TREE_USED (newdecl) = 1;
261938fd1498Szrj   else if (TREE_USED (newdecl))
262038fd1498Szrj     TREE_USED (olddecl) = 1;
262138fd1498Szrj   if (VAR_P (olddecl) || TREE_CODE (olddecl) == PARM_DECL)
262238fd1498Szrj     DECL_READ_P (newdecl) |= DECL_READ_P (olddecl);
262338fd1498Szrj   if (DECL_PRESERVE_P (olddecl))
262438fd1498Szrj     DECL_PRESERVE_P (newdecl) = 1;
262538fd1498Szrj   else if (DECL_PRESERVE_P (newdecl))
262638fd1498Szrj     DECL_PRESERVE_P (olddecl) = 1;
262738fd1498Szrj 
262838fd1498Szrj   /* Merge DECL_COMMON */
262938fd1498Szrj   if (VAR_P (olddecl) && VAR_P (newdecl)
263038fd1498Szrj       && !lookup_attribute ("common", DECL_ATTRIBUTES (newdecl))
263138fd1498Szrj       && !lookup_attribute ("nocommon", DECL_ATTRIBUTES (newdecl)))
263238fd1498Szrj     DECL_COMMON (newdecl) = DECL_COMMON (newdecl) && DECL_COMMON (olddecl);
263338fd1498Szrj 
263438fd1498Szrj   /* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
263538fd1498Szrj      But preserve OLDDECL's DECL_UID, DECL_CONTEXT and
263638fd1498Szrj      DECL_ARGUMENTS (if appropriate).  */
263738fd1498Szrj   {
263838fd1498Szrj     unsigned olddecl_uid = DECL_UID (olddecl);
263938fd1498Szrj     tree olddecl_context = DECL_CONTEXT (olddecl);
264038fd1498Szrj     tree olddecl_arguments = NULL;
264138fd1498Szrj     if (TREE_CODE (olddecl) == FUNCTION_DECL)
264238fd1498Szrj       olddecl_arguments = DECL_ARGUMENTS (olddecl);
264338fd1498Szrj 
264438fd1498Szrj     memcpy ((char *) olddecl + sizeof (struct tree_common),
264538fd1498Szrj 	    (char *) newdecl + sizeof (struct tree_common),
264638fd1498Szrj 	    sizeof (struct tree_decl_common) - sizeof (struct tree_common));
264738fd1498Szrj     DECL_USER_ALIGN (olddecl) = DECL_USER_ALIGN (newdecl);
264838fd1498Szrj     switch (TREE_CODE (olddecl))
264938fd1498Szrj       {
265038fd1498Szrj       case FUNCTION_DECL:
265138fd1498Szrj       case VAR_DECL:
265238fd1498Szrj 	{
265338fd1498Szrj 	  struct symtab_node *snode = olddecl->decl_with_vis.symtab_node;
265438fd1498Szrj 
265538fd1498Szrj 	  memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
265638fd1498Szrj 		  (char *) newdecl + sizeof (struct tree_decl_common),
265738fd1498Szrj 		  tree_code_size (TREE_CODE (olddecl)) - sizeof (struct tree_decl_common));
265838fd1498Szrj 	  olddecl->decl_with_vis.symtab_node = snode;
265938fd1498Szrj 
266038fd1498Szrj 	  if ((DECL_EXTERNAL (olddecl)
266138fd1498Szrj 	       || TREE_PUBLIC (olddecl)
266238fd1498Szrj 	       || TREE_STATIC (olddecl))
266338fd1498Szrj 	      && DECL_SECTION_NAME (newdecl) != NULL)
266438fd1498Szrj 	    set_decl_section_name (olddecl, DECL_SECTION_NAME (newdecl));
266538fd1498Szrj 
266638fd1498Szrj 	  /* This isn't quite correct for something like
266738fd1498Szrj 		int __thread x attribute ((tls_model ("local-exec")));
266838fd1498Szrj 		extern int __thread x;
266938fd1498Szrj 	     as we'll lose the "local-exec" model.  */
267038fd1498Szrj 	  if (VAR_P (olddecl) && DECL_THREAD_LOCAL_P (newdecl))
267138fd1498Szrj 	    set_decl_tls_model (olddecl, DECL_TLS_MODEL (newdecl));
267238fd1498Szrj 	  break;
267338fd1498Szrj 	}
267438fd1498Szrj 
267538fd1498Szrj       case FIELD_DECL:
267638fd1498Szrj       case PARM_DECL:
267738fd1498Szrj       case LABEL_DECL:
267838fd1498Szrj       case RESULT_DECL:
267938fd1498Szrj       case CONST_DECL:
268038fd1498Szrj       case TYPE_DECL:
268138fd1498Szrj 	memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
268238fd1498Szrj 		(char *) newdecl + sizeof (struct tree_decl_common),
268338fd1498Szrj 		tree_code_size (TREE_CODE (olddecl)) - sizeof (struct tree_decl_common));
268438fd1498Szrj 	break;
268538fd1498Szrj 
268638fd1498Szrj       default:
268738fd1498Szrj 
268838fd1498Szrj 	memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
268938fd1498Szrj 		(char *) newdecl + sizeof (struct tree_decl_common),
269038fd1498Szrj 		sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common));
269138fd1498Szrj       }
269238fd1498Szrj     DECL_UID (olddecl) = olddecl_uid;
269338fd1498Szrj     DECL_CONTEXT (olddecl) = olddecl_context;
269438fd1498Szrj     if (TREE_CODE (olddecl) == FUNCTION_DECL)
269538fd1498Szrj       DECL_ARGUMENTS (olddecl) = olddecl_arguments;
269638fd1498Szrj   }
269738fd1498Szrj 
269838fd1498Szrj   /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
269938fd1498Szrj      so that encode_section_info has a chance to look at the new decl
270038fd1498Szrj      flags and attributes.  */
270138fd1498Szrj   if (DECL_RTL_SET_P (olddecl)
270238fd1498Szrj       && (TREE_CODE (olddecl) == FUNCTION_DECL
270338fd1498Szrj 	  || (VAR_P (olddecl) && TREE_STATIC (olddecl))))
270438fd1498Szrj     make_decl_rtl (olddecl);
270538fd1498Szrj }
270638fd1498Szrj 
270738fd1498Szrj /* Handle when a new declaration NEWDECL has the same name as an old
270838fd1498Szrj    one OLDDECL in the same binding contour.  Prints an error message
270938fd1498Szrj    if appropriate.
271038fd1498Szrj 
271138fd1498Szrj    If safely possible, alter OLDDECL to look like NEWDECL, and return
271238fd1498Szrj    true.  Otherwise, return false.  */
271338fd1498Szrj 
271438fd1498Szrj static bool
duplicate_decls(tree newdecl,tree olddecl)271538fd1498Szrj duplicate_decls (tree newdecl, tree olddecl)
271638fd1498Szrj {
271738fd1498Szrj   tree newtype = NULL, oldtype = NULL;
271838fd1498Szrj 
271938fd1498Szrj   if (!diagnose_mismatched_decls (newdecl, olddecl, &newtype, &oldtype))
272038fd1498Szrj     {
272138fd1498Szrj       /* Avoid `unused variable' and other warnings for OLDDECL.  */
272238fd1498Szrj       TREE_NO_WARNING (olddecl) = 1;
272338fd1498Szrj       return false;
272438fd1498Szrj     }
272538fd1498Szrj 
272638fd1498Szrj   merge_decls (newdecl, olddecl, newtype, oldtype);
272738fd1498Szrj 
272838fd1498Szrj   /* The NEWDECL will no longer be needed.
272938fd1498Szrj 
273038fd1498Szrj      Before releasing the node, be sure to remove function from symbol
273138fd1498Szrj      table that might have been inserted there to record comdat group.
273238fd1498Szrj      Be sure to however do not free DECL_STRUCT_FUNCTION because this
273338fd1498Szrj      structure is shared in between NEWDECL and OLDECL.  */
273438fd1498Szrj   if (TREE_CODE (newdecl) == FUNCTION_DECL)
273538fd1498Szrj     DECL_STRUCT_FUNCTION (newdecl) = NULL;
273638fd1498Szrj   if (VAR_OR_FUNCTION_DECL_P (newdecl))
273738fd1498Szrj     {
273838fd1498Szrj       struct symtab_node *snode = symtab_node::get (newdecl);
273938fd1498Szrj       if (snode)
274038fd1498Szrj 	snode->remove ();
274138fd1498Szrj     }
274238fd1498Szrj   ggc_free (newdecl);
274338fd1498Szrj   return true;
274438fd1498Szrj }
274538fd1498Szrj 
274638fd1498Szrj 
274738fd1498Szrj /* Check whether decl-node NEW_DECL shadows an existing declaration.  */
274838fd1498Szrj static void
warn_if_shadowing(tree new_decl)274938fd1498Szrj warn_if_shadowing (tree new_decl)
275038fd1498Szrj {
275138fd1498Szrj   struct c_binding *b;
275238fd1498Szrj 
275338fd1498Szrj   /* Shadow warnings wanted?  */
275438fd1498Szrj   if (!(warn_shadow
275538fd1498Szrj         || warn_shadow_local
275638fd1498Szrj         || warn_shadow_compatible_local)
275738fd1498Szrj       /* No shadow warnings for internally generated vars.  */
275838fd1498Szrj       || DECL_IS_BUILTIN (new_decl)
275938fd1498Szrj       /* No shadow warnings for vars made for inlining.  */
276038fd1498Szrj       || DECL_FROM_INLINE (new_decl))
276138fd1498Szrj     return;
276238fd1498Szrj 
276338fd1498Szrj   /* Is anything being shadowed?  Invisible decls do not count.  */
276438fd1498Szrj   for (b = I_SYMBOL_BINDING (DECL_NAME (new_decl)); b; b = b->shadowed)
276538fd1498Szrj     if (b->decl && b->decl != new_decl && !b->invisible
276638fd1498Szrj 	&& (b->decl == error_mark_node
276738fd1498Szrj 	    || diagnostic_report_warnings_p (global_dc,
276838fd1498Szrj 					     DECL_SOURCE_LOCATION (b->decl))))
276938fd1498Szrj       {
277038fd1498Szrj 	tree old_decl = b->decl;
277138fd1498Szrj 	bool warned = false;
277238fd1498Szrj 
277338fd1498Szrj 	if (old_decl == error_mark_node)
277438fd1498Szrj 	  {
277538fd1498Szrj 	    warning (OPT_Wshadow, "declaration of %q+D shadows previous "
277638fd1498Szrj 		     "non-variable", new_decl);
277738fd1498Szrj 	    break;
277838fd1498Szrj 	  }
277938fd1498Szrj 	else if (TREE_CODE (old_decl) == PARM_DECL)
278038fd1498Szrj 	  {
278138fd1498Szrj 	    enum opt_code warning_code;
278238fd1498Szrj 
278338fd1498Szrj 	    /* If '-Wshadow=compatible-local' is specified without other
278438fd1498Szrj 	       -Wshadow= flags, we will warn only when the types of the
278538fd1498Szrj 	       shadowing variable (i.e. new_decl) and the shadowed variable
278638fd1498Szrj 	       (old_decl) are compatible.  */
278738fd1498Szrj 	    if (warn_shadow)
278838fd1498Szrj 	      warning_code = OPT_Wshadow;
278938fd1498Szrj 	    else if (comptypes (TREE_TYPE (old_decl), TREE_TYPE (new_decl)))
279038fd1498Szrj 	      warning_code = OPT_Wshadow_compatible_local;
279138fd1498Szrj 	    else
279238fd1498Szrj 	      warning_code = OPT_Wshadow_local;
279338fd1498Szrj 	    warned = warning_at (DECL_SOURCE_LOCATION (new_decl), warning_code,
279438fd1498Szrj 				 "declaration of %qD shadows a parameter",
279538fd1498Szrj 				 new_decl);
279638fd1498Szrj 	  }
279738fd1498Szrj 	else if (DECL_FILE_SCOPE_P (old_decl))
279838fd1498Szrj 	  {
279938fd1498Szrj 	    /* Do not warn if a variable shadows a function, unless
280038fd1498Szrj 	       the variable is a function or a pointer-to-function.  */
280138fd1498Szrj 	    if (TREE_CODE (old_decl) == FUNCTION_DECL
280238fd1498Szrj 		&& TREE_CODE (new_decl) != FUNCTION_DECL
280338fd1498Szrj 		&& !FUNCTION_POINTER_TYPE_P (TREE_TYPE (new_decl)))
280438fd1498Szrj 		continue;
280538fd1498Szrj 
280638fd1498Szrj 	    warned = warning_at (DECL_SOURCE_LOCATION (new_decl), OPT_Wshadow,
280738fd1498Szrj 				 "declaration of %qD shadows a global "
280838fd1498Szrj 				 "declaration",
280938fd1498Szrj 				 new_decl);
281038fd1498Szrj 	  }
281138fd1498Szrj 	else if (TREE_CODE (old_decl) == FUNCTION_DECL
281238fd1498Szrj 		 && DECL_BUILT_IN (old_decl))
281338fd1498Szrj 	  {
281438fd1498Szrj 	    warning (OPT_Wshadow, "declaration of %q+D shadows "
281538fd1498Szrj 		     "a built-in function", new_decl);
281638fd1498Szrj 	    break;
281738fd1498Szrj 	  }
281838fd1498Szrj 	else
281938fd1498Szrj 	  {
282038fd1498Szrj 	    enum opt_code warning_code;
282138fd1498Szrj 
282238fd1498Szrj 	    /* If '-Wshadow=compatible-local' is specified without other
282338fd1498Szrj 	       -Wshadow= flags, we will warn only when the types of the
282438fd1498Szrj 	       shadowing variable (i.e. new_decl) and the shadowed variable
282538fd1498Szrj 	       (old_decl) are compatible.  */
282638fd1498Szrj 	    if (warn_shadow)
282738fd1498Szrj 	      warning_code = OPT_Wshadow;
282838fd1498Szrj 	    else if (comptypes (TREE_TYPE (old_decl), TREE_TYPE (new_decl)))
282938fd1498Szrj 	      warning_code = OPT_Wshadow_compatible_local;
283038fd1498Szrj 	    else
283138fd1498Szrj 	      warning_code = OPT_Wshadow_local;
283238fd1498Szrj 	    warned = warning_at (DECL_SOURCE_LOCATION (new_decl), warning_code,
283338fd1498Szrj 				 "declaration of %qD shadows a previous local",
283438fd1498Szrj 				 new_decl);
283538fd1498Szrj 	  }
283638fd1498Szrj 
283738fd1498Szrj 	if (warned)
283838fd1498Szrj 	  inform (DECL_SOURCE_LOCATION (old_decl),
283938fd1498Szrj 		  "shadowed declaration is here");
284038fd1498Szrj 
284138fd1498Szrj 	break;
284238fd1498Szrj       }
284338fd1498Szrj }
284438fd1498Szrj 
284538fd1498Szrj /* Record a decl-node X as belonging to the current lexical scope.
284638fd1498Szrj    Check for errors (such as an incompatible declaration for the same
284738fd1498Szrj    name already seen in the same scope).
284838fd1498Szrj 
284938fd1498Szrj    Returns either X or an old decl for the same name.
285038fd1498Szrj    If an old decl is returned, it may have been smashed
285138fd1498Szrj    to agree with what X says.  */
285238fd1498Szrj 
285338fd1498Szrj tree
pushdecl(tree x)285438fd1498Szrj pushdecl (tree x)
285538fd1498Szrj {
285638fd1498Szrj   tree name = DECL_NAME (x);
285738fd1498Szrj   struct c_scope *scope = current_scope;
285838fd1498Szrj   struct c_binding *b;
285938fd1498Szrj   bool nested = false;
286038fd1498Szrj   location_t locus = DECL_SOURCE_LOCATION (x);
286138fd1498Szrj 
286238fd1498Szrj   /* Must set DECL_CONTEXT for everything not at file scope or
286338fd1498Szrj      DECL_FILE_SCOPE_P won't work.  Local externs don't count
286438fd1498Szrj      unless they have initializers (which generate code).  */
286538fd1498Szrj   if (current_function_decl
286638fd1498Szrj       && (!VAR_OR_FUNCTION_DECL_P (x)
286738fd1498Szrj 	  || DECL_INITIAL (x) || !DECL_EXTERNAL (x)))
286838fd1498Szrj     DECL_CONTEXT (x) = current_function_decl;
286938fd1498Szrj 
287038fd1498Szrj   /* Anonymous decls are just inserted in the scope.  */
287138fd1498Szrj   if (!name)
287238fd1498Szrj     {
287338fd1498Szrj       bind (name, x, scope, /*invisible=*/false, /*nested=*/false,
287438fd1498Szrj 	    locus);
287538fd1498Szrj       return x;
287638fd1498Szrj     }
287738fd1498Szrj 
287838fd1498Szrj   /* First, see if there is another declaration with the same name in
287938fd1498Szrj      the current scope.  If there is, duplicate_decls may do all the
288038fd1498Szrj      work for us.  If duplicate_decls returns false, that indicates
288138fd1498Szrj      two incompatible decls in the same scope; we are to silently
288238fd1498Szrj      replace the old one (duplicate_decls has issued all appropriate
288338fd1498Szrj      diagnostics).  In particular, we should not consider possible
288438fd1498Szrj      duplicates in the external scope, or shadowing.  */
288538fd1498Szrj   b = I_SYMBOL_BINDING (name);
288638fd1498Szrj   if (b && B_IN_SCOPE (b, scope))
288738fd1498Szrj     {
288838fd1498Szrj       struct c_binding *b_ext, *b_use;
288938fd1498Szrj       tree type = TREE_TYPE (x);
289038fd1498Szrj       tree visdecl = b->decl;
289138fd1498Szrj       tree vistype = TREE_TYPE (visdecl);
289238fd1498Szrj       if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
289338fd1498Szrj 	  && COMPLETE_TYPE_P (TREE_TYPE (x)))
289438fd1498Szrj 	b->inner_comp = false;
289538fd1498Szrj       b_use = b;
289638fd1498Szrj       b_ext = b;
289738fd1498Szrj       /* If this is an external linkage declaration, we should check
289838fd1498Szrj 	 for compatibility with the type in the external scope before
289938fd1498Szrj 	 setting the type at this scope based on the visible
290038fd1498Szrj 	 information only.  */
290138fd1498Szrj       if (TREE_PUBLIC (x) && TREE_PUBLIC (visdecl))
290238fd1498Szrj 	{
290338fd1498Szrj 	  while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext))
290438fd1498Szrj 	    b_ext = b_ext->shadowed;
290538fd1498Szrj 	  if (b_ext)
290638fd1498Szrj 	    {
290738fd1498Szrj 	      b_use = b_ext;
290838fd1498Szrj 	      if (b_use->u.type)
290938fd1498Szrj 		TREE_TYPE (b_use->decl) = b_use->u.type;
291038fd1498Szrj 	    }
291138fd1498Szrj 	}
291238fd1498Szrj       if (duplicate_decls (x, b_use->decl))
291338fd1498Szrj 	{
291438fd1498Szrj 	  if (b_use != b)
291538fd1498Szrj 	    {
291638fd1498Szrj 	      /* Save the updated type in the external scope and
291738fd1498Szrj 		 restore the proper type for this scope.  */
291838fd1498Szrj 	      tree thistype;
291938fd1498Szrj 	      if (comptypes (vistype, type))
292038fd1498Szrj 		thistype = composite_type (vistype, type);
292138fd1498Szrj 	      else
292238fd1498Szrj 		thistype = TREE_TYPE (b_use->decl);
292338fd1498Szrj 	      b_use->u.type = TREE_TYPE (b_use->decl);
292438fd1498Szrj 	      if (TREE_CODE (b_use->decl) == FUNCTION_DECL
292538fd1498Szrj 		  && DECL_BUILT_IN (b_use->decl))
292638fd1498Szrj 		thistype
292738fd1498Szrj 		  = build_type_attribute_variant (thistype,
292838fd1498Szrj 						  TYPE_ATTRIBUTES
292938fd1498Szrj 						  (b_use->u.type));
293038fd1498Szrj 	      TREE_TYPE (b_use->decl) = thistype;
293138fd1498Szrj 	    }
293238fd1498Szrj 	  return b_use->decl;
293338fd1498Szrj 	}
293438fd1498Szrj       else
293538fd1498Szrj 	goto skip_external_and_shadow_checks;
293638fd1498Szrj     }
293738fd1498Szrj 
293838fd1498Szrj   /* All declarations with external linkage, and all external
293938fd1498Szrj      references, go in the external scope, no matter what scope is
294038fd1498Szrj      current.  However, the binding in that scope is ignored for
294138fd1498Szrj      purposes of normal name lookup.  A separate binding structure is
294238fd1498Szrj      created in the requested scope; this governs the normal
294338fd1498Szrj      visibility of the symbol.
294438fd1498Szrj 
294538fd1498Szrj      The binding in the externals scope is used exclusively for
294638fd1498Szrj      detecting duplicate declarations of the same object, no matter
294738fd1498Szrj      what scope they are in; this is what we do here.  (C99 6.2.7p2:
294838fd1498Szrj      All declarations that refer to the same object or function shall
294938fd1498Szrj      have compatible type; otherwise, the behavior is undefined.)  */
295038fd1498Szrj   if (DECL_EXTERNAL (x) || scope == file_scope)
295138fd1498Szrj     {
295238fd1498Szrj       tree type = TREE_TYPE (x);
295338fd1498Szrj       tree vistype = NULL_TREE;
295438fd1498Szrj       tree visdecl = NULL_TREE;
295538fd1498Szrj       bool type_saved = false;
295638fd1498Szrj       if (b && !B_IN_EXTERNAL_SCOPE (b)
295738fd1498Szrj 	  && VAR_OR_FUNCTION_DECL_P (b->decl)
295838fd1498Szrj 	  && DECL_FILE_SCOPE_P (b->decl))
295938fd1498Szrj 	{
296038fd1498Szrj 	  visdecl = b->decl;
296138fd1498Szrj 	  vistype = TREE_TYPE (visdecl);
296238fd1498Szrj 	}
296338fd1498Szrj       if (scope != file_scope
296438fd1498Szrj 	  && !DECL_IN_SYSTEM_HEADER (x))
296538fd1498Szrj 	warning_at (locus, OPT_Wnested_externs,
296638fd1498Szrj 		    "nested extern declaration of %qD", x);
296738fd1498Szrj 
296838fd1498Szrj       while (b && !B_IN_EXTERNAL_SCOPE (b))
296938fd1498Szrj 	{
297038fd1498Szrj 	  /* If this decl might be modified, save its type.  This is
297138fd1498Szrj 	     done here rather than when the decl is first bound
297238fd1498Szrj 	     because the type may change after first binding, through
297338fd1498Szrj 	     being completed or through attributes being added.  If we
297438fd1498Szrj 	     encounter multiple such decls, only the first should have
297538fd1498Szrj 	     its type saved; the others will already have had their
297638fd1498Szrj 	     proper types saved and the types will not have changed as
297738fd1498Szrj 	     their scopes will not have been re-entered.  */
297838fd1498Szrj 	  if (DECL_P (b->decl) && DECL_FILE_SCOPE_P (b->decl) && !type_saved)
297938fd1498Szrj 	    {
298038fd1498Szrj 	      b->u.type = TREE_TYPE (b->decl);
298138fd1498Szrj 	      type_saved = true;
298238fd1498Szrj 	    }
298338fd1498Szrj 	  if (B_IN_FILE_SCOPE (b)
298438fd1498Szrj 	      && VAR_P (b->decl)
298538fd1498Szrj 	      && TREE_STATIC (b->decl)
298638fd1498Szrj 	      && TREE_CODE (TREE_TYPE (b->decl)) == ARRAY_TYPE
298738fd1498Szrj 	      && !TYPE_DOMAIN (TREE_TYPE (b->decl))
298838fd1498Szrj 	      && TREE_CODE (type) == ARRAY_TYPE
298938fd1498Szrj 	      && TYPE_DOMAIN (type)
299038fd1498Szrj 	      && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
299138fd1498Szrj 	      && !integer_zerop (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
299238fd1498Szrj 	    {
299338fd1498Szrj 	      /* Array type completed in inner scope, which should be
299438fd1498Szrj 		 diagnosed if the completion does not have size 1 and
299538fd1498Szrj 		 it does not get completed in the file scope.  */
299638fd1498Szrj 	      b->inner_comp = true;
299738fd1498Szrj 	    }
299838fd1498Szrj 	  b = b->shadowed;
299938fd1498Szrj 	}
300038fd1498Szrj 
300138fd1498Szrj       /* If a matching external declaration has been found, set its
300238fd1498Szrj 	 type to the composite of all the types of that declaration.
300338fd1498Szrj 	 After the consistency checks, it will be reset to the
300438fd1498Szrj 	 composite of the visible types only.  */
300538fd1498Szrj       if (b && (TREE_PUBLIC (x) || same_translation_unit_p (x, b->decl))
300638fd1498Szrj 	  && b->u.type)
300738fd1498Szrj 	TREE_TYPE (b->decl) = b->u.type;
300838fd1498Szrj 
300938fd1498Szrj       /* The point of the same_translation_unit_p check here is,
301038fd1498Szrj 	 we want to detect a duplicate decl for a construct like
301138fd1498Szrj 	 foo() { extern bar(); } ... static bar();  but not if
301238fd1498Szrj 	 they are in different translation units.  In any case,
301338fd1498Szrj 	 the static does not go in the externals scope.  */
301438fd1498Szrj       if (b
301538fd1498Szrj 	  && (TREE_PUBLIC (x) || same_translation_unit_p (x, b->decl))
301638fd1498Szrj 	  && duplicate_decls (x, b->decl))
301738fd1498Szrj 	{
301838fd1498Szrj 	  tree thistype;
301938fd1498Szrj 	  if (vistype)
302038fd1498Szrj 	    {
302138fd1498Szrj 	      if (comptypes (vistype, type))
302238fd1498Szrj 		thistype = composite_type (vistype, type);
302338fd1498Szrj 	      else
302438fd1498Szrj 		thistype = TREE_TYPE (b->decl);
302538fd1498Szrj 	    }
302638fd1498Szrj 	  else
302738fd1498Szrj 	    thistype = type;
302838fd1498Szrj 	  b->u.type = TREE_TYPE (b->decl);
302938fd1498Szrj 	  if (TREE_CODE (b->decl) == FUNCTION_DECL && DECL_BUILT_IN (b->decl))
303038fd1498Szrj 	    thistype
303138fd1498Szrj 	      = build_type_attribute_variant (thistype,
303238fd1498Szrj 					      TYPE_ATTRIBUTES (b->u.type));
303338fd1498Szrj 	  TREE_TYPE (b->decl) = thistype;
303438fd1498Szrj 	  bind (name, b->decl, scope, /*invisible=*/false, /*nested=*/true,
303538fd1498Szrj 		locus);
303638fd1498Szrj 	  return b->decl;
303738fd1498Szrj 	}
303838fd1498Szrj       else if (TREE_PUBLIC (x))
303938fd1498Szrj 	{
304038fd1498Szrj 	  if (visdecl && !b && duplicate_decls (x, visdecl))
304138fd1498Szrj 	    {
304238fd1498Szrj 	      /* An external declaration at block scope referring to a
304338fd1498Szrj 		 visible entity with internal linkage.  The composite
304438fd1498Szrj 		 type will already be correct for this scope, so we
304538fd1498Szrj 		 just need to fall through to make the declaration in
304638fd1498Szrj 		 this scope.  */
304738fd1498Szrj 	      nested = true;
304838fd1498Szrj 	      x = visdecl;
304938fd1498Szrj 	    }
305038fd1498Szrj 	  else
305138fd1498Szrj 	    {
305238fd1498Szrj 	      bind (name, x, external_scope, /*invisible=*/true,
305338fd1498Szrj 		    /*nested=*/false, locus);
305438fd1498Szrj 	      nested = true;
305538fd1498Szrj 	    }
305638fd1498Szrj 	}
305738fd1498Szrj     }
305838fd1498Szrj 
305938fd1498Szrj   if (TREE_CODE (x) != PARM_DECL)
306038fd1498Szrj     warn_if_shadowing (x);
306138fd1498Szrj 
306238fd1498Szrj  skip_external_and_shadow_checks:
306338fd1498Szrj   if (TREE_CODE (x) == TYPE_DECL)
306438fd1498Szrj     {
306538fd1498Szrj       /* So this is a typedef, set its underlying type.  */
306638fd1498Szrj       set_underlying_type (x);
306738fd1498Szrj 
306838fd1498Szrj       /* If X is a typedef defined in the current function, record it
306938fd1498Szrj 	 for the purpose of implementing the -Wunused-local-typedefs
307038fd1498Szrj 	 warning.  */
307138fd1498Szrj       record_locally_defined_typedef (x);
307238fd1498Szrj     }
307338fd1498Szrj 
307438fd1498Szrj   bind (name, x, scope, /*invisible=*/false, nested, locus);
307538fd1498Szrj 
307638fd1498Szrj   /* If x's type is incomplete because it's based on a
307738fd1498Szrj      structure or union which has not yet been fully declared,
307838fd1498Szrj      attach it to that structure or union type, so we can go
307938fd1498Szrj      back and complete the variable declaration later, if the
308038fd1498Szrj      structure or union gets fully declared.
308138fd1498Szrj 
308238fd1498Szrj      If the input is erroneous, we can have error_mark in the type
308338fd1498Szrj      slot (e.g. "f(void a, ...)") - that doesn't count as an
308438fd1498Szrj      incomplete type.  */
308538fd1498Szrj   if (TREE_TYPE (x) != error_mark_node
308638fd1498Szrj       && !COMPLETE_TYPE_P (TREE_TYPE (x)))
308738fd1498Szrj     {
308838fd1498Szrj       tree element = TREE_TYPE (x);
308938fd1498Szrj 
309038fd1498Szrj       while (TREE_CODE (element) == ARRAY_TYPE)
309138fd1498Szrj 	element = TREE_TYPE (element);
309238fd1498Szrj       element = TYPE_MAIN_VARIANT (element);
309338fd1498Szrj 
309438fd1498Szrj       if (RECORD_OR_UNION_TYPE_P (element)
309538fd1498Szrj 	  && (TREE_CODE (x) != TYPE_DECL
309638fd1498Szrj 	      || TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE)
309738fd1498Szrj 	  && !COMPLETE_TYPE_P (element))
309838fd1498Szrj 	C_TYPE_INCOMPLETE_VARS (element)
309938fd1498Szrj 	  = tree_cons (NULL_TREE, x, C_TYPE_INCOMPLETE_VARS (element));
310038fd1498Szrj     }
310138fd1498Szrj   return x;
310238fd1498Szrj }
310338fd1498Szrj 
310438fd1498Szrj 
310538fd1498Szrj /* Issue a warning about implicit function declaration.  ID is the function
310638fd1498Szrj    identifier, OLDDECL is a declaration of the function in a different scope,
310738fd1498Szrj    or NULL_TREE.  */
310838fd1498Szrj 
310938fd1498Szrj static void
implicit_decl_warning(location_t loc,tree id,tree olddecl)311038fd1498Szrj implicit_decl_warning (location_t loc, tree id, tree olddecl)
311138fd1498Szrj {
311238fd1498Szrj   if (!warn_implicit_function_declaration)
311338fd1498Szrj     return;
311438fd1498Szrj 
311538fd1498Szrj   bool warned;
311638fd1498Szrj   name_hint hint;
311738fd1498Szrj   if (!olddecl)
311838fd1498Szrj     hint = lookup_name_fuzzy (id, FUZZY_LOOKUP_FUNCTION_NAME, loc);
311938fd1498Szrj 
312038fd1498Szrj   if (flag_isoc99)
312138fd1498Szrj     {
312238fd1498Szrj       if (hint)
312338fd1498Szrj 	{
312438fd1498Szrj 	  gcc_rich_location richloc (loc);
312538fd1498Szrj 	  richloc.add_fixit_replace (hint.suggestion ());
312638fd1498Szrj 	  warned = pedwarn (&richloc, OPT_Wimplicit_function_declaration,
312738fd1498Szrj 			    "implicit declaration of function %qE;"
312838fd1498Szrj 			    " did you mean %qs?",
312938fd1498Szrj 			    id, hint.suggestion ());
313038fd1498Szrj 	}
313138fd1498Szrj       else
313238fd1498Szrj 	warned = pedwarn (loc, OPT_Wimplicit_function_declaration,
313338fd1498Szrj 			  "implicit declaration of function %qE", id);
313438fd1498Szrj     }
313538fd1498Szrj   else if (hint)
313638fd1498Szrj     {
313738fd1498Szrj       gcc_rich_location richloc (loc);
313838fd1498Szrj       richloc.add_fixit_replace (hint.suggestion ());
313938fd1498Szrj       warned = warning_at
314038fd1498Szrj 	(&richloc, OPT_Wimplicit_function_declaration,
314138fd1498Szrj 	 G_("implicit declaration of function %qE; did you mean %qs?"),
314238fd1498Szrj 	 id, hint.suggestion ());
314338fd1498Szrj     }
314438fd1498Szrj   else
314538fd1498Szrj     warned = warning_at (loc, OPT_Wimplicit_function_declaration,
314638fd1498Szrj 			 G_("implicit declaration of function %qE"), id);
314738fd1498Szrj 
314838fd1498Szrj   if (olddecl && warned)
314938fd1498Szrj     locate_old_decl (olddecl);
315038fd1498Szrj 
315138fd1498Szrj   if (!warned)
315238fd1498Szrj     hint.suppress ();
315338fd1498Szrj }
315438fd1498Szrj 
315538fd1498Szrj /* This function represents mapping of a function code FCODE
315638fd1498Szrj    to its respective header.  */
315738fd1498Szrj 
315838fd1498Szrj static const char *
header_for_builtin_fn(enum built_in_function fcode)315938fd1498Szrj header_for_builtin_fn (enum built_in_function fcode)
316038fd1498Szrj {
316138fd1498Szrj   switch (fcode)
316238fd1498Szrj     {
316338fd1498Szrj     CASE_FLT_FN (BUILT_IN_ACOS):
316438fd1498Szrj     CASE_FLT_FN (BUILT_IN_ACOSH):
316538fd1498Szrj     CASE_FLT_FN (BUILT_IN_ASIN):
316638fd1498Szrj     CASE_FLT_FN (BUILT_IN_ASINH):
316738fd1498Szrj     CASE_FLT_FN (BUILT_IN_ATAN):
316838fd1498Szrj     CASE_FLT_FN (BUILT_IN_ATANH):
316938fd1498Szrj     CASE_FLT_FN (BUILT_IN_ATAN2):
317038fd1498Szrj     CASE_FLT_FN (BUILT_IN_CBRT):
317138fd1498Szrj     CASE_FLT_FN (BUILT_IN_CEIL):
317238fd1498Szrj     CASE_FLT_FN_FLOATN_NX (BUILT_IN_CEIL):
317338fd1498Szrj     CASE_FLT_FN (BUILT_IN_COPYSIGN):
317438fd1498Szrj     CASE_FLT_FN_FLOATN_NX (BUILT_IN_COPYSIGN):
317538fd1498Szrj     CASE_FLT_FN (BUILT_IN_COS):
317638fd1498Szrj     CASE_FLT_FN (BUILT_IN_COSH):
317738fd1498Szrj     CASE_FLT_FN (BUILT_IN_ERF):
317838fd1498Szrj     CASE_FLT_FN (BUILT_IN_ERFC):
317938fd1498Szrj     CASE_FLT_FN (BUILT_IN_EXP):
318038fd1498Szrj     CASE_FLT_FN (BUILT_IN_EXP2):
318138fd1498Szrj     CASE_FLT_FN (BUILT_IN_EXPM1):
318238fd1498Szrj     CASE_FLT_FN (BUILT_IN_FABS):
318338fd1498Szrj     CASE_FLT_FN_FLOATN_NX (BUILT_IN_FABS):
318438fd1498Szrj     CASE_FLT_FN (BUILT_IN_FDIM):
318538fd1498Szrj     CASE_FLT_FN (BUILT_IN_FLOOR):
318638fd1498Szrj     CASE_FLT_FN_FLOATN_NX (BUILT_IN_FLOOR):
318738fd1498Szrj     CASE_FLT_FN (BUILT_IN_FMA):
318838fd1498Szrj     CASE_FLT_FN_FLOATN_NX (BUILT_IN_FMA):
318938fd1498Szrj     CASE_FLT_FN (BUILT_IN_FMAX):
319038fd1498Szrj     CASE_FLT_FN_FLOATN_NX (BUILT_IN_FMAX):
319138fd1498Szrj     CASE_FLT_FN (BUILT_IN_FMIN):
319238fd1498Szrj     CASE_FLT_FN_FLOATN_NX (BUILT_IN_FMIN):
319338fd1498Szrj     CASE_FLT_FN (BUILT_IN_FMOD):
319438fd1498Szrj     CASE_FLT_FN (BUILT_IN_FREXP):
319538fd1498Szrj     CASE_FLT_FN (BUILT_IN_HYPOT):
319638fd1498Szrj     CASE_FLT_FN (BUILT_IN_ILOGB):
319738fd1498Szrj     CASE_FLT_FN (BUILT_IN_LDEXP):
319838fd1498Szrj     CASE_FLT_FN (BUILT_IN_LGAMMA):
319938fd1498Szrj     CASE_FLT_FN (BUILT_IN_LLRINT):
320038fd1498Szrj     CASE_FLT_FN (BUILT_IN_LLROUND):
320138fd1498Szrj     CASE_FLT_FN (BUILT_IN_LOG):
320238fd1498Szrj     CASE_FLT_FN (BUILT_IN_LOG10):
320338fd1498Szrj     CASE_FLT_FN (BUILT_IN_LOG1P):
320438fd1498Szrj     CASE_FLT_FN (BUILT_IN_LOG2):
320538fd1498Szrj     CASE_FLT_FN (BUILT_IN_LOGB):
320638fd1498Szrj     CASE_FLT_FN (BUILT_IN_LRINT):
320738fd1498Szrj     CASE_FLT_FN (BUILT_IN_LROUND):
320838fd1498Szrj     CASE_FLT_FN (BUILT_IN_MODF):
320938fd1498Szrj     CASE_FLT_FN (BUILT_IN_NAN):
321038fd1498Szrj     CASE_FLT_FN (BUILT_IN_NEARBYINT):
321138fd1498Szrj     CASE_FLT_FN_FLOATN_NX (BUILT_IN_NEARBYINT):
321238fd1498Szrj     CASE_FLT_FN (BUILT_IN_NEXTAFTER):
321338fd1498Szrj     CASE_FLT_FN (BUILT_IN_NEXTTOWARD):
321438fd1498Szrj     CASE_FLT_FN (BUILT_IN_POW):
321538fd1498Szrj     CASE_FLT_FN (BUILT_IN_REMAINDER):
321638fd1498Szrj     CASE_FLT_FN (BUILT_IN_REMQUO):
321738fd1498Szrj     CASE_FLT_FN (BUILT_IN_RINT):
321838fd1498Szrj     CASE_FLT_FN_FLOATN_NX (BUILT_IN_RINT):
321938fd1498Szrj     CASE_FLT_FN (BUILT_IN_ROUND):
322038fd1498Szrj     CASE_FLT_FN_FLOATN_NX (BUILT_IN_ROUND):
322138fd1498Szrj     CASE_FLT_FN (BUILT_IN_SCALBLN):
322238fd1498Szrj     CASE_FLT_FN (BUILT_IN_SCALBN):
322338fd1498Szrj     CASE_FLT_FN (BUILT_IN_SIN):
322438fd1498Szrj     CASE_FLT_FN (BUILT_IN_SINH):
322538fd1498Szrj     CASE_FLT_FN (BUILT_IN_SINCOS):
322638fd1498Szrj     CASE_FLT_FN (BUILT_IN_SQRT):
322738fd1498Szrj     CASE_FLT_FN_FLOATN_NX (BUILT_IN_SQRT):
322838fd1498Szrj     CASE_FLT_FN (BUILT_IN_TAN):
322938fd1498Szrj     CASE_FLT_FN (BUILT_IN_TANH):
323038fd1498Szrj     CASE_FLT_FN (BUILT_IN_TGAMMA):
323138fd1498Szrj     CASE_FLT_FN (BUILT_IN_TRUNC):
323238fd1498Szrj     CASE_FLT_FN_FLOATN_NX (BUILT_IN_TRUNC):
323338fd1498Szrj     case BUILT_IN_ISINF:
323438fd1498Szrj     case BUILT_IN_ISNAN:
323538fd1498Szrj       return "<math.h>";
323638fd1498Szrj     CASE_FLT_FN (BUILT_IN_CABS):
323738fd1498Szrj     CASE_FLT_FN (BUILT_IN_CACOS):
323838fd1498Szrj     CASE_FLT_FN (BUILT_IN_CACOSH):
323938fd1498Szrj     CASE_FLT_FN (BUILT_IN_CARG):
324038fd1498Szrj     CASE_FLT_FN (BUILT_IN_CASIN):
324138fd1498Szrj     CASE_FLT_FN (BUILT_IN_CASINH):
324238fd1498Szrj     CASE_FLT_FN (BUILT_IN_CATAN):
324338fd1498Szrj     CASE_FLT_FN (BUILT_IN_CATANH):
324438fd1498Szrj     CASE_FLT_FN (BUILT_IN_CCOS):
324538fd1498Szrj     CASE_FLT_FN (BUILT_IN_CCOSH):
324638fd1498Szrj     CASE_FLT_FN (BUILT_IN_CEXP):
324738fd1498Szrj     CASE_FLT_FN (BUILT_IN_CIMAG):
324838fd1498Szrj     CASE_FLT_FN (BUILT_IN_CLOG):
324938fd1498Szrj     CASE_FLT_FN (BUILT_IN_CONJ):
325038fd1498Szrj     CASE_FLT_FN (BUILT_IN_CPOW):
325138fd1498Szrj     CASE_FLT_FN (BUILT_IN_CPROJ):
325238fd1498Szrj     CASE_FLT_FN (BUILT_IN_CREAL):
325338fd1498Szrj     CASE_FLT_FN (BUILT_IN_CSIN):
325438fd1498Szrj     CASE_FLT_FN (BUILT_IN_CSINH):
325538fd1498Szrj     CASE_FLT_FN (BUILT_IN_CSQRT):
325638fd1498Szrj     CASE_FLT_FN (BUILT_IN_CTAN):
325738fd1498Szrj     CASE_FLT_FN (BUILT_IN_CTANH):
325838fd1498Szrj       return "<complex.h>";
325938fd1498Szrj     case BUILT_IN_MEMCHR:
326038fd1498Szrj     case BUILT_IN_MEMCMP:
326138fd1498Szrj     case BUILT_IN_MEMCPY:
326238fd1498Szrj     case BUILT_IN_MEMMOVE:
326338fd1498Szrj     case BUILT_IN_MEMSET:
326438fd1498Szrj     case BUILT_IN_STRCAT:
326538fd1498Szrj     case BUILT_IN_STRCHR:
326638fd1498Szrj     case BUILT_IN_STRCMP:
326738fd1498Szrj     case BUILT_IN_STRCPY:
326838fd1498Szrj     case BUILT_IN_STRCSPN:
326938fd1498Szrj     case BUILT_IN_STRLEN:
327038fd1498Szrj     case BUILT_IN_STRNCAT:
327138fd1498Szrj     case BUILT_IN_STRNCMP:
327238fd1498Szrj     case BUILT_IN_STRNCPY:
327338fd1498Szrj     case BUILT_IN_STRPBRK:
327438fd1498Szrj     case BUILT_IN_STRRCHR:
327538fd1498Szrj     case BUILT_IN_STRSPN:
327638fd1498Szrj     case BUILT_IN_STRSTR:
327738fd1498Szrj       return "<string.h>";
327838fd1498Szrj     case BUILT_IN_FPRINTF:
327938fd1498Szrj     case BUILT_IN_PUTC:
328038fd1498Szrj     case BUILT_IN_FPUTC:
328138fd1498Szrj     case BUILT_IN_FPUTS:
328238fd1498Szrj     case BUILT_IN_FSCANF:
328338fd1498Szrj     case BUILT_IN_FWRITE:
328438fd1498Szrj     case BUILT_IN_PRINTF:
328538fd1498Szrj     case BUILT_IN_PUTCHAR:
328638fd1498Szrj     case BUILT_IN_PUTS:
328738fd1498Szrj     case BUILT_IN_SCANF:
328838fd1498Szrj     case BUILT_IN_SNPRINTF:
328938fd1498Szrj     case BUILT_IN_SPRINTF:
329038fd1498Szrj     case BUILT_IN_SSCANF:
329138fd1498Szrj     case BUILT_IN_VFPRINTF:
329238fd1498Szrj     case BUILT_IN_VFSCANF:
329338fd1498Szrj     case BUILT_IN_VPRINTF:
329438fd1498Szrj     case BUILT_IN_VSCANF:
329538fd1498Szrj     case BUILT_IN_VSNPRINTF:
329638fd1498Szrj     case BUILT_IN_VSPRINTF:
329738fd1498Szrj     case BUILT_IN_VSSCANF:
329838fd1498Szrj       return "<stdio.h>";
329938fd1498Szrj     case BUILT_IN_ISALNUM:
330038fd1498Szrj     case BUILT_IN_ISALPHA:
330138fd1498Szrj     case BUILT_IN_ISBLANK:
330238fd1498Szrj     case BUILT_IN_ISCNTRL:
330338fd1498Szrj     case BUILT_IN_ISDIGIT:
330438fd1498Szrj     case BUILT_IN_ISGRAPH:
330538fd1498Szrj     case BUILT_IN_ISLOWER:
330638fd1498Szrj     case BUILT_IN_ISPRINT:
330738fd1498Szrj     case BUILT_IN_ISPUNCT:
330838fd1498Szrj     case BUILT_IN_ISSPACE:
330938fd1498Szrj     case BUILT_IN_ISUPPER:
331038fd1498Szrj     case BUILT_IN_ISXDIGIT:
331138fd1498Szrj     case BUILT_IN_TOLOWER:
331238fd1498Szrj     case BUILT_IN_TOUPPER:
331338fd1498Szrj       return "<ctype.h>";
331438fd1498Szrj     case BUILT_IN_ISWALNUM:
331538fd1498Szrj     case BUILT_IN_ISWALPHA:
331638fd1498Szrj     case BUILT_IN_ISWBLANK:
331738fd1498Szrj     case BUILT_IN_ISWCNTRL:
331838fd1498Szrj     case BUILT_IN_ISWDIGIT:
331938fd1498Szrj     case BUILT_IN_ISWGRAPH:
332038fd1498Szrj     case BUILT_IN_ISWLOWER:
332138fd1498Szrj     case BUILT_IN_ISWPRINT:
332238fd1498Szrj     case BUILT_IN_ISWPUNCT:
332338fd1498Szrj     case BUILT_IN_ISWSPACE:
332438fd1498Szrj     case BUILT_IN_ISWUPPER:
332538fd1498Szrj     case BUILT_IN_ISWXDIGIT:
332638fd1498Szrj     case BUILT_IN_TOWLOWER:
332738fd1498Szrj     case BUILT_IN_TOWUPPER:
332838fd1498Szrj       return "<wctype.h>";
332938fd1498Szrj     case BUILT_IN_ABORT:
333038fd1498Szrj     case BUILT_IN_ABS:
333138fd1498Szrj     case BUILT_IN_CALLOC:
333238fd1498Szrj     case BUILT_IN_EXIT:
333338fd1498Szrj     case BUILT_IN_FREE:
333438fd1498Szrj     case BUILT_IN_LABS:
333538fd1498Szrj     case BUILT_IN_LLABS:
333638fd1498Szrj     case BUILT_IN_MALLOC:
333738fd1498Szrj     case BUILT_IN_REALLOC:
333838fd1498Szrj     case BUILT_IN__EXIT2:
333938fd1498Szrj     case BUILT_IN_ALIGNED_ALLOC:
334038fd1498Szrj       return "<stdlib.h>";
334138fd1498Szrj     case BUILT_IN_IMAXABS:
334238fd1498Szrj       return "<inttypes.h>";
334338fd1498Szrj     case BUILT_IN_STRFTIME:
334438fd1498Szrj       return "<time.h>";
334538fd1498Szrj     default:
334638fd1498Szrj       return NULL;
334738fd1498Szrj     }
334838fd1498Szrj }
334938fd1498Szrj 
335038fd1498Szrj /* Generate an implicit declaration for identifier FUNCTIONID at LOC as a
335138fd1498Szrj    function of type int ().  */
335238fd1498Szrj 
335338fd1498Szrj tree
implicitly_declare(location_t loc,tree functionid)335438fd1498Szrj implicitly_declare (location_t loc, tree functionid)
335538fd1498Szrj {
335638fd1498Szrj   struct c_binding *b;
335738fd1498Szrj   tree decl = NULL_TREE;
335838fd1498Szrj   tree asmspec_tree;
335938fd1498Szrj 
336038fd1498Szrj   for (b = I_SYMBOL_BINDING (functionid); b; b = b->shadowed)
336138fd1498Szrj     {
336238fd1498Szrj       if (B_IN_SCOPE (b, external_scope))
336338fd1498Szrj 	{
336438fd1498Szrj 	  decl = b->decl;
336538fd1498Szrj 	  break;
336638fd1498Szrj 	}
336738fd1498Szrj     }
336838fd1498Szrj 
336938fd1498Szrj   if (decl)
337038fd1498Szrj     {
337138fd1498Szrj       if (TREE_CODE (decl) != FUNCTION_DECL)
337238fd1498Szrj 	return decl;
337338fd1498Szrj 
337438fd1498Szrj       /* FIXME: Objective-C has weird not-really-builtin functions
337538fd1498Szrj 	 which are supposed to be visible automatically.  They wind up
337638fd1498Szrj 	 in the external scope because they're pushed before the file
337738fd1498Szrj 	 scope gets created.  Catch this here and rebind them into the
337838fd1498Szrj 	 file scope.  */
337938fd1498Szrj       if (!DECL_BUILT_IN (decl) && DECL_IS_BUILTIN (decl))
338038fd1498Szrj 	{
338138fd1498Szrj 	  bind (functionid, decl, file_scope,
338238fd1498Szrj 		/*invisible=*/false, /*nested=*/true,
338338fd1498Szrj 		DECL_SOURCE_LOCATION (decl));
338438fd1498Szrj 	  return decl;
338538fd1498Szrj 	}
338638fd1498Szrj       else
338738fd1498Szrj 	{
338838fd1498Szrj 	  tree newtype = default_function_type;
338938fd1498Szrj 	  if (b->u.type)
339038fd1498Szrj 	    TREE_TYPE (decl) = b->u.type;
339138fd1498Szrj 	  /* Implicit declaration of a function already declared
339238fd1498Szrj 	     (somehow) in a different scope, or as a built-in.
339338fd1498Szrj 	     If this is the first time this has happened, warn;
339438fd1498Szrj 	     then recycle the old declaration but with the new type.  */
339538fd1498Szrj 	  if (!C_DECL_IMPLICIT (decl))
339638fd1498Szrj 	    {
339738fd1498Szrj 	      implicit_decl_warning (loc, functionid, decl);
339838fd1498Szrj 	      C_DECL_IMPLICIT (decl) = 1;
339938fd1498Szrj 	    }
340038fd1498Szrj 	  if (DECL_BUILT_IN (decl))
340138fd1498Szrj 	    {
340238fd1498Szrj 	      newtype = build_type_attribute_variant (newtype,
340338fd1498Szrj 						      TYPE_ATTRIBUTES
340438fd1498Szrj 						      (TREE_TYPE (decl)));
340538fd1498Szrj 	      if (!comptypes (newtype, TREE_TYPE (decl)))
340638fd1498Szrj 		{
340738fd1498Szrj 		  bool warned = warning_at (loc, 0, "incompatible implicit "
340838fd1498Szrj 					    "declaration of built-in "
340938fd1498Szrj 					    "function %qD", decl);
341038fd1498Szrj 		  /* See if we can hint which header to include.  */
341138fd1498Szrj 		  const char *header
341238fd1498Szrj 		    = header_for_builtin_fn (DECL_FUNCTION_CODE (decl));
341338fd1498Szrj 		  if (header != NULL && warned)
341438fd1498Szrj 		    {
341538fd1498Szrj 		      rich_location richloc (line_table, loc);
341638fd1498Szrj 		      maybe_add_include_fixit (&richloc, header);
341738fd1498Szrj 		      inform (&richloc,
341838fd1498Szrj 			      "include %qs or provide a declaration of %qD",
341938fd1498Szrj 			      header, decl);
342038fd1498Szrj 		    }
342138fd1498Szrj 		  newtype = TREE_TYPE (decl);
342238fd1498Szrj 		}
342338fd1498Szrj 	    }
342438fd1498Szrj 	  else
342538fd1498Szrj 	    {
342638fd1498Szrj 	      if (!comptypes (newtype, TREE_TYPE (decl)))
342738fd1498Szrj 		{
342838fd1498Szrj 		  error_at (loc, "incompatible implicit declaration of "
342938fd1498Szrj 			    "function %qD", decl);
343038fd1498Szrj 		  locate_old_decl (decl);
343138fd1498Szrj 		}
343238fd1498Szrj 	    }
343338fd1498Szrj 	  b->u.type = TREE_TYPE (decl);
343438fd1498Szrj 	  TREE_TYPE (decl) = newtype;
343538fd1498Szrj 	  bind (functionid, decl, current_scope,
343638fd1498Szrj 		/*invisible=*/false, /*nested=*/true,
343738fd1498Szrj 		DECL_SOURCE_LOCATION (decl));
343838fd1498Szrj 	  return decl;
343938fd1498Szrj 	}
344038fd1498Szrj     }
344138fd1498Szrj 
344238fd1498Szrj   /* Not seen before.  */
344338fd1498Szrj   decl = build_decl (loc, FUNCTION_DECL, functionid, default_function_type);
344438fd1498Szrj   DECL_EXTERNAL (decl) = 1;
344538fd1498Szrj   TREE_PUBLIC (decl) = 1;
344638fd1498Szrj   C_DECL_IMPLICIT (decl) = 1;
344738fd1498Szrj   implicit_decl_warning (loc, functionid, 0);
344838fd1498Szrj   asmspec_tree = maybe_apply_renaming_pragma (decl, /*asmname=*/NULL);
344938fd1498Szrj   if (asmspec_tree)
345038fd1498Szrj     set_user_assembler_name (decl, TREE_STRING_POINTER (asmspec_tree));
345138fd1498Szrj 
345238fd1498Szrj   /* C89 says implicit declarations are in the innermost block.
345338fd1498Szrj      So we record the decl in the standard fashion.  */
345438fd1498Szrj   decl = pushdecl (decl);
345538fd1498Szrj 
345638fd1498Szrj   /* No need to call objc_check_decl here - it's a function type.  */
345738fd1498Szrj   rest_of_decl_compilation (decl, 0, 0);
345838fd1498Szrj 
345938fd1498Szrj   /* Write a record describing this implicit function declaration
346038fd1498Szrj      to the prototypes file (if requested).  */
346138fd1498Szrj   gen_aux_info_record (decl, 0, 1, 0);
346238fd1498Szrj 
346338fd1498Szrj   /* Possibly apply some default attributes to this implicit declaration.  */
346438fd1498Szrj   decl_attributes (&decl, NULL_TREE, 0);
346538fd1498Szrj 
346638fd1498Szrj   return decl;
346738fd1498Szrj }
346838fd1498Szrj 
346938fd1498Szrj /* Issue an error message for a reference to an undeclared variable
347038fd1498Szrj    ID, including a reference to a builtin outside of function-call
347138fd1498Szrj    context.  Establish a binding of the identifier to error_mark_node
347238fd1498Szrj    in an appropriate scope, which will suppress further errors for the
347338fd1498Szrj    same identifier.  The error message should be given location LOC.  */
347438fd1498Szrj void
undeclared_variable(location_t loc,tree id)347538fd1498Szrj undeclared_variable (location_t loc, tree id)
347638fd1498Szrj {
347738fd1498Szrj   static bool already = false;
347838fd1498Szrj   struct c_scope *scope;
347938fd1498Szrj 
348038fd1498Szrj   if (current_function_decl == NULL_TREE)
348138fd1498Szrj     {
348238fd1498Szrj       name_hint guessed_id = lookup_name_fuzzy (id, FUZZY_LOOKUP_NAME, loc);
348338fd1498Szrj       if (guessed_id)
348438fd1498Szrj 	{
348538fd1498Szrj 	  gcc_rich_location richloc (loc);
348638fd1498Szrj 	  richloc.add_fixit_replace (guessed_id.suggestion ());
348738fd1498Szrj 	  error_at (&richloc,
348838fd1498Szrj 		    "%qE undeclared here (not in a function);"
348938fd1498Szrj 		    " did you mean %qs?",
349038fd1498Szrj 		    id, guessed_id.suggestion ());
349138fd1498Szrj 	}
349238fd1498Szrj       else
349338fd1498Szrj 	error_at (loc, "%qE undeclared here (not in a function)", id);
349438fd1498Szrj       scope = current_scope;
349538fd1498Szrj     }
349638fd1498Szrj   else
349738fd1498Szrj     {
349838fd1498Szrj       if (!objc_diagnose_private_ivar (id))
349938fd1498Szrj 	{
350038fd1498Szrj 	  name_hint guessed_id = lookup_name_fuzzy (id, FUZZY_LOOKUP_NAME, loc);
350138fd1498Szrj 	  if (guessed_id)
350238fd1498Szrj 	    {
350338fd1498Szrj 	      gcc_rich_location richloc (loc);
350438fd1498Szrj 	      richloc.add_fixit_replace (guessed_id.suggestion ());
350538fd1498Szrj 	      error_at (&richloc,
350638fd1498Szrj 			"%qE undeclared (first use in this function);"
350738fd1498Szrj 			" did you mean %qs?",
350838fd1498Szrj 			id, guessed_id.suggestion ());
350938fd1498Szrj 	    }
351038fd1498Szrj 	  else
351138fd1498Szrj 	    error_at (loc, "%qE undeclared (first use in this function)", id);
351238fd1498Szrj 	}
351338fd1498Szrj       if (!already)
351438fd1498Szrj 	{
351538fd1498Szrj           inform (loc, "each undeclared identifier is reported only"
351638fd1498Szrj                   " once for each function it appears in");
351738fd1498Szrj 	  already = true;
351838fd1498Szrj 	}
351938fd1498Szrj 
352038fd1498Szrj       /* If we are parsing old-style parameter decls, current_function_decl
352138fd1498Szrj 	 will be nonnull but current_function_scope will be null.  */
352238fd1498Szrj       scope = current_function_scope ? current_function_scope : current_scope;
352338fd1498Szrj     }
352438fd1498Szrj   bind (id, error_mark_node, scope, /*invisible=*/false, /*nested=*/false,
352538fd1498Szrj 	UNKNOWN_LOCATION);
352638fd1498Szrj }
352738fd1498Szrj 
352838fd1498Szrj /* Subroutine of lookup_label, declare_label, define_label: construct a
352938fd1498Szrj    LABEL_DECL with all the proper frills.  Also create a struct
353038fd1498Szrj    c_label_vars initialized for the current scope.  */
353138fd1498Szrj 
353238fd1498Szrj static tree
make_label(location_t location,tree name,bool defining,struct c_label_vars ** p_label_vars)353338fd1498Szrj make_label (location_t location, tree name, bool defining,
353438fd1498Szrj 	    struct c_label_vars **p_label_vars)
353538fd1498Szrj {
353638fd1498Szrj   tree label = build_decl (location, LABEL_DECL, name, void_type_node);
353738fd1498Szrj   DECL_CONTEXT (label) = current_function_decl;
353838fd1498Szrj   SET_DECL_MODE (label, VOIDmode);
353938fd1498Szrj 
354038fd1498Szrj   c_label_vars *label_vars = ggc_alloc<c_label_vars> ();
354138fd1498Szrj   label_vars->shadowed = NULL;
354238fd1498Szrj   set_spot_bindings (&label_vars->label_bindings, defining);
354338fd1498Szrj   label_vars->decls_in_scope = make_tree_vector ();
354438fd1498Szrj   label_vars->gotos = NULL;
354538fd1498Szrj   *p_label_vars = label_vars;
354638fd1498Szrj 
354738fd1498Szrj   return label;
354838fd1498Szrj }
354938fd1498Szrj 
355038fd1498Szrj /* Get the LABEL_DECL corresponding to identifier NAME as a label.
355138fd1498Szrj    Create one if none exists so far for the current function.
355238fd1498Szrj    This is called when a label is used in a goto expression or
355338fd1498Szrj    has its address taken.  */
355438fd1498Szrj 
355538fd1498Szrj tree
lookup_label(tree name)355638fd1498Szrj lookup_label (tree name)
355738fd1498Szrj {
355838fd1498Szrj   tree label;
355938fd1498Szrj   struct c_label_vars *label_vars;
356038fd1498Szrj 
356138fd1498Szrj   if (current_function_scope == 0)
356238fd1498Szrj     {
356338fd1498Szrj       error ("label %qE referenced outside of any function", name);
356438fd1498Szrj       return NULL_TREE;
356538fd1498Szrj     }
356638fd1498Szrj 
356738fd1498Szrj   /* Use a label already defined or ref'd with this name, but not if
356838fd1498Szrj      it is inherited from a containing function and wasn't declared
356938fd1498Szrj      using __label__.  */
357038fd1498Szrj   label = I_LABEL_DECL (name);
357138fd1498Szrj   if (label && (DECL_CONTEXT (label) == current_function_decl
357238fd1498Szrj 		|| C_DECLARED_LABEL_FLAG (label)))
357338fd1498Szrj     {
357438fd1498Szrj       /* If the label has only been declared, update its apparent
357538fd1498Szrj 	 location to point here, for better diagnostics if it
357638fd1498Szrj 	 turns out not to have been defined.  */
357738fd1498Szrj       if (DECL_INITIAL (label) == NULL_TREE)
357838fd1498Szrj 	DECL_SOURCE_LOCATION (label) = input_location;
357938fd1498Szrj       return label;
358038fd1498Szrj     }
358138fd1498Szrj 
358238fd1498Szrj   /* No label binding for that identifier; make one.  */
358338fd1498Szrj   label = make_label (input_location, name, false, &label_vars);
358438fd1498Szrj 
358538fd1498Szrj   /* Ordinary labels go in the current function scope.  */
358638fd1498Szrj   bind_label (name, label, current_function_scope, label_vars);
358738fd1498Szrj 
358838fd1498Szrj   return label;
358938fd1498Szrj }
359038fd1498Szrj 
359138fd1498Szrj /* Issue a warning about DECL for a goto statement at GOTO_LOC going
359238fd1498Szrj    to LABEL.  */
359338fd1498Szrj 
359438fd1498Szrj static void
warn_about_goto(location_t goto_loc,tree label,tree decl)359538fd1498Szrj warn_about_goto (location_t goto_loc, tree label, tree decl)
359638fd1498Szrj {
359738fd1498Szrj   if (variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
359838fd1498Szrj     error_at (goto_loc,
359938fd1498Szrj 	      "jump into scope of identifier with variably modified type");
360038fd1498Szrj   else
360138fd1498Szrj     warning_at (goto_loc, OPT_Wjump_misses_init,
360238fd1498Szrj 		"jump skips variable initialization");
360338fd1498Szrj   inform (DECL_SOURCE_LOCATION (label), "label %qD defined here", label);
360438fd1498Szrj   inform (DECL_SOURCE_LOCATION (decl), "%qD declared here", decl);
360538fd1498Szrj }
360638fd1498Szrj 
360738fd1498Szrj /* Look up a label because of a goto statement.  This is like
360838fd1498Szrj    lookup_label, but also issues any appropriate warnings.  */
360938fd1498Szrj 
361038fd1498Szrj tree
lookup_label_for_goto(location_t loc,tree name)361138fd1498Szrj lookup_label_for_goto (location_t loc, tree name)
361238fd1498Szrj {
361338fd1498Szrj   tree label;
361438fd1498Szrj   struct c_label_vars *label_vars;
361538fd1498Szrj   unsigned int ix;
361638fd1498Szrj   tree decl;
361738fd1498Szrj 
361838fd1498Szrj   label = lookup_label (name);
361938fd1498Szrj   if (label == NULL_TREE)
362038fd1498Szrj     return NULL_TREE;
362138fd1498Szrj 
362238fd1498Szrj   /* If we are jumping to a different function, we can't issue any
362338fd1498Szrj      useful warnings.  */
362438fd1498Szrj   if (DECL_CONTEXT (label) != current_function_decl)
362538fd1498Szrj     {
362638fd1498Szrj       gcc_assert (C_DECLARED_LABEL_FLAG (label));
362738fd1498Szrj       return label;
362838fd1498Szrj     }
362938fd1498Szrj 
363038fd1498Szrj   label_vars = I_LABEL_BINDING (name)->u.label;
363138fd1498Szrj 
363238fd1498Szrj   /* If the label has not yet been defined, then push this goto on a
363338fd1498Szrj      list for possible later warnings.  */
363438fd1498Szrj   if (label_vars->label_bindings.scope == NULL)
363538fd1498Szrj     {
363638fd1498Szrj       c_goto_bindings *g = ggc_alloc<c_goto_bindings> ();
363738fd1498Szrj 
363838fd1498Szrj       g->loc = loc;
363938fd1498Szrj       set_spot_bindings (&g->goto_bindings, true);
364038fd1498Szrj       vec_safe_push (label_vars->gotos, g);
364138fd1498Szrj       return label;
364238fd1498Szrj     }
364338fd1498Szrj 
364438fd1498Szrj   /* If there are any decls in label_vars->decls_in_scope, then this
364538fd1498Szrj      goto has missed the declaration of the decl.  This happens for a
364638fd1498Szrj      case like
364738fd1498Szrj        int i = 1;
364838fd1498Szrj       lab:
364938fd1498Szrj        ...
365038fd1498Szrj        goto lab;
365138fd1498Szrj      Issue a warning or error.  */
365238fd1498Szrj   FOR_EACH_VEC_SAFE_ELT (label_vars->decls_in_scope, ix, decl)
365338fd1498Szrj     warn_about_goto (loc, label, decl);
365438fd1498Szrj 
365538fd1498Szrj   if (label_vars->label_bindings.left_stmt_expr)
365638fd1498Szrj     {
365738fd1498Szrj       error_at (loc, "jump into statement expression");
365838fd1498Szrj       inform (DECL_SOURCE_LOCATION (label), "label %qD defined here", label);
365938fd1498Szrj     }
366038fd1498Szrj 
366138fd1498Szrj   return label;
366238fd1498Szrj }
366338fd1498Szrj 
366438fd1498Szrj /* Make a label named NAME in the current function, shadowing silently
366538fd1498Szrj    any that may be inherited from containing functions or containing
366638fd1498Szrj    scopes.  This is called for __label__ declarations.  */
366738fd1498Szrj 
366838fd1498Szrj tree
declare_label(tree name)366938fd1498Szrj declare_label (tree name)
367038fd1498Szrj {
367138fd1498Szrj   struct c_binding *b = I_LABEL_BINDING (name);
367238fd1498Szrj   tree label;
367338fd1498Szrj   struct c_label_vars *label_vars;
367438fd1498Szrj 
367538fd1498Szrj   /* Check to make sure that the label hasn't already been declared
367638fd1498Szrj      at this scope */
367738fd1498Szrj   if (b && B_IN_CURRENT_SCOPE (b))
367838fd1498Szrj     {
367938fd1498Szrj       error ("duplicate label declaration %qE", name);
368038fd1498Szrj       locate_old_decl (b->decl);
368138fd1498Szrj 
368238fd1498Szrj       /* Just use the previous declaration.  */
368338fd1498Szrj       return b->decl;
368438fd1498Szrj     }
368538fd1498Szrj 
368638fd1498Szrj   label = make_label (input_location, name, false, &label_vars);
368738fd1498Szrj   C_DECLARED_LABEL_FLAG (label) = 1;
368838fd1498Szrj 
368938fd1498Szrj   /* Declared labels go in the current scope.  */
369038fd1498Szrj   bind_label (name, label, current_scope, label_vars);
369138fd1498Szrj 
369238fd1498Szrj   return label;
369338fd1498Szrj }
369438fd1498Szrj 
369538fd1498Szrj /* When we define a label, issue any appropriate warnings if there are
369638fd1498Szrj    any gotos earlier in the function which jump to this label.  */
369738fd1498Szrj 
369838fd1498Szrj static void
check_earlier_gotos(tree label,struct c_label_vars * label_vars)369938fd1498Szrj check_earlier_gotos (tree label, struct c_label_vars* label_vars)
370038fd1498Szrj {
370138fd1498Szrj   unsigned int ix;
370238fd1498Szrj   struct c_goto_bindings *g;
370338fd1498Szrj 
370438fd1498Szrj   FOR_EACH_VEC_SAFE_ELT (label_vars->gotos, ix, g)
370538fd1498Szrj     {
370638fd1498Szrj       struct c_binding *b;
370738fd1498Szrj       struct c_scope *scope;
370838fd1498Szrj 
370938fd1498Szrj       /* We have a goto to this label.  The goto is going forward.  In
371038fd1498Szrj 	 g->scope, the goto is going to skip any binding which was
371138fd1498Szrj 	 defined after g->bindings_in_scope.  */
371238fd1498Szrj       if (g->goto_bindings.scope->has_jump_unsafe_decl)
371338fd1498Szrj 	{
371438fd1498Szrj 	  for (b = g->goto_bindings.scope->bindings;
371538fd1498Szrj 	       b != g->goto_bindings.bindings_in_scope;
371638fd1498Szrj 	       b = b->prev)
371738fd1498Szrj 	    {
371838fd1498Szrj 	      if (decl_jump_unsafe (b->decl))
371938fd1498Szrj 		warn_about_goto (g->loc, label, b->decl);
372038fd1498Szrj 	    }
372138fd1498Szrj 	}
372238fd1498Szrj 
372338fd1498Szrj       /* We also need to warn about decls defined in any scopes
372438fd1498Szrj 	 between the scope of the label and the scope of the goto.  */
372538fd1498Szrj       for (scope = label_vars->label_bindings.scope;
372638fd1498Szrj 	   scope != g->goto_bindings.scope;
372738fd1498Szrj 	   scope = scope->outer)
372838fd1498Szrj 	{
372938fd1498Szrj 	  gcc_assert (scope != NULL);
373038fd1498Szrj 	  if (scope->has_jump_unsafe_decl)
373138fd1498Szrj 	    {
373238fd1498Szrj 	      if (scope == label_vars->label_bindings.scope)
373338fd1498Szrj 		b = label_vars->label_bindings.bindings_in_scope;
373438fd1498Szrj 	      else
373538fd1498Szrj 		b = scope->bindings;
373638fd1498Szrj 	      for (; b != NULL; b = b->prev)
373738fd1498Szrj 		{
373838fd1498Szrj 		  if (decl_jump_unsafe (b->decl))
373938fd1498Szrj 		    warn_about_goto (g->loc, label, b->decl);
374038fd1498Szrj 		}
374138fd1498Szrj 	    }
374238fd1498Szrj 	}
374338fd1498Szrj 
374438fd1498Szrj       if (g->goto_bindings.stmt_exprs > 0)
374538fd1498Szrj 	{
374638fd1498Szrj 	  error_at (g->loc, "jump into statement expression");
374738fd1498Szrj 	  inform (DECL_SOURCE_LOCATION (label), "label %qD defined here",
374838fd1498Szrj 		  label);
374938fd1498Szrj 	}
375038fd1498Szrj     }
375138fd1498Szrj 
375238fd1498Szrj   /* Now that the label is defined, we will issue warnings about
375338fd1498Szrj      subsequent gotos to this label when we see them.  */
375438fd1498Szrj   vec_safe_truncate (label_vars->gotos, 0);
375538fd1498Szrj   label_vars->gotos = NULL;
375638fd1498Szrj }
375738fd1498Szrj 
375838fd1498Szrj /* Define a label, specifying the location in the source file.
375938fd1498Szrj    Return the LABEL_DECL node for the label, if the definition is valid.
376038fd1498Szrj    Otherwise return NULL_TREE.  */
376138fd1498Szrj 
376238fd1498Szrj tree
define_label(location_t location,tree name)376338fd1498Szrj define_label (location_t location, tree name)
376438fd1498Szrj {
376538fd1498Szrj   /* Find any preexisting label with this name.  It is an error
376638fd1498Szrj      if that label has already been defined in this function, or
376738fd1498Szrj      if there is a containing function with a declared label with
376838fd1498Szrj      the same name.  */
376938fd1498Szrj   tree label = I_LABEL_DECL (name);
377038fd1498Szrj 
377138fd1498Szrj   if (label
377238fd1498Szrj       && ((DECL_CONTEXT (label) == current_function_decl
377338fd1498Szrj 	   && DECL_INITIAL (label) != NULL_TREE)
377438fd1498Szrj 	  || (DECL_CONTEXT (label) != current_function_decl
377538fd1498Szrj 	      && C_DECLARED_LABEL_FLAG (label))))
377638fd1498Szrj     {
377738fd1498Szrj       error_at (location, "duplicate label %qD", label);
377838fd1498Szrj       locate_old_decl (label);
377938fd1498Szrj       return NULL_TREE;
378038fd1498Szrj     }
378138fd1498Szrj   else if (label && DECL_CONTEXT (label) == current_function_decl)
378238fd1498Szrj     {
378338fd1498Szrj       struct c_label_vars *label_vars = I_LABEL_BINDING (name)->u.label;
378438fd1498Szrj 
378538fd1498Szrj       /* The label has been used or declared already in this function,
378638fd1498Szrj 	 but not defined.  Update its location to point to this
378738fd1498Szrj 	 definition.  */
378838fd1498Szrj       DECL_SOURCE_LOCATION (label) = location;
378938fd1498Szrj       set_spot_bindings (&label_vars->label_bindings, true);
379038fd1498Szrj 
379138fd1498Szrj       /* Issue warnings as required about any goto statements from
379238fd1498Szrj 	 earlier in the function.  */
379338fd1498Szrj       check_earlier_gotos (label, label_vars);
379438fd1498Szrj     }
379538fd1498Szrj   else
379638fd1498Szrj     {
379738fd1498Szrj       struct c_label_vars *label_vars;
379838fd1498Szrj 
379938fd1498Szrj       /* No label binding for that identifier; make one.  */
380038fd1498Szrj       label = make_label (location, name, true, &label_vars);
380138fd1498Szrj 
380238fd1498Szrj       /* Ordinary labels go in the current function scope.  */
380338fd1498Szrj       bind_label (name, label, current_function_scope, label_vars);
380438fd1498Szrj     }
380538fd1498Szrj 
380638fd1498Szrj   if (!in_system_header_at (input_location) && lookup_name (name))
380738fd1498Szrj     warning_at (location, OPT_Wtraditional,
380838fd1498Szrj 		"traditional C lacks a separate namespace "
380938fd1498Szrj 		"for labels, identifier %qE conflicts", name);
381038fd1498Szrj 
381138fd1498Szrj   /* Mark label as having been defined.  */
381238fd1498Szrj   DECL_INITIAL (label) = error_mark_node;
381338fd1498Szrj   return label;
381438fd1498Szrj }
381538fd1498Szrj 
381638fd1498Szrj /* Get the bindings for a new switch statement.  This is used to issue
381738fd1498Szrj    warnings as appropriate for jumps from the switch to case or
381838fd1498Szrj    default labels.  */
381938fd1498Szrj 
382038fd1498Szrj struct c_spot_bindings *
c_get_switch_bindings(void)382138fd1498Szrj c_get_switch_bindings (void)
382238fd1498Szrj {
382338fd1498Szrj   struct c_spot_bindings *switch_bindings;
382438fd1498Szrj 
382538fd1498Szrj   switch_bindings = XNEW (struct c_spot_bindings);
382638fd1498Szrj   set_spot_bindings (switch_bindings, true);
382738fd1498Szrj   return switch_bindings;
382838fd1498Szrj }
382938fd1498Szrj 
383038fd1498Szrj void
c_release_switch_bindings(struct c_spot_bindings * bindings)383138fd1498Szrj c_release_switch_bindings (struct c_spot_bindings *bindings)
383238fd1498Szrj {
383338fd1498Szrj   gcc_assert (bindings->stmt_exprs == 0 && !bindings->left_stmt_expr);
383438fd1498Szrj   XDELETE (bindings);
383538fd1498Szrj }
383638fd1498Szrj 
383738fd1498Szrj /* This is called at the point of a case or default label to issue
383838fd1498Szrj    warnings about decls as needed.  It returns true if it found an
383938fd1498Szrj    error, not just a warning.  */
384038fd1498Szrj 
384138fd1498Szrj bool
c_check_switch_jump_warnings(struct c_spot_bindings * switch_bindings,location_t switch_loc,location_t case_loc)384238fd1498Szrj c_check_switch_jump_warnings (struct c_spot_bindings *switch_bindings,
384338fd1498Szrj 			      location_t switch_loc, location_t case_loc)
384438fd1498Szrj {
384538fd1498Szrj   bool saw_error;
384638fd1498Szrj   struct c_scope *scope;
384738fd1498Szrj 
384838fd1498Szrj   saw_error = false;
384938fd1498Szrj   for (scope = current_scope;
385038fd1498Szrj        scope != switch_bindings->scope;
385138fd1498Szrj        scope = scope->outer)
385238fd1498Szrj     {
385338fd1498Szrj       struct c_binding *b;
385438fd1498Szrj 
385538fd1498Szrj       gcc_assert (scope != NULL);
385638fd1498Szrj 
385738fd1498Szrj       if (!scope->has_jump_unsafe_decl)
385838fd1498Szrj 	continue;
385938fd1498Szrj 
386038fd1498Szrj       for (b = scope->bindings; b != NULL; b = b->prev)
386138fd1498Szrj 	{
386238fd1498Szrj 	  if (decl_jump_unsafe (b->decl))
386338fd1498Szrj 	    {
386438fd1498Szrj 	      if (variably_modified_type_p (TREE_TYPE (b->decl), NULL_TREE))
386538fd1498Szrj 		{
386638fd1498Szrj 		  saw_error = true;
386738fd1498Szrj 		  error_at (case_loc,
386838fd1498Szrj 			    ("switch jumps into scope of identifier with "
386938fd1498Szrj 			     "variably modified type"));
387038fd1498Szrj 		}
387138fd1498Szrj 	      else
387238fd1498Szrj 		warning_at (case_loc, OPT_Wjump_misses_init,
387338fd1498Szrj 			    "switch jumps over variable initialization");
387438fd1498Szrj 	      inform (switch_loc, "switch starts here");
387538fd1498Szrj 	      inform (DECL_SOURCE_LOCATION (b->decl), "%qD declared here",
387638fd1498Szrj 		      b->decl);
387738fd1498Szrj 	    }
387838fd1498Szrj 	}
387938fd1498Szrj     }
388038fd1498Szrj 
388138fd1498Szrj   if (switch_bindings->stmt_exprs > 0)
388238fd1498Szrj     {
388338fd1498Szrj       saw_error = true;
388438fd1498Szrj       error_at (case_loc, "switch jumps into statement expression");
388538fd1498Szrj       inform (switch_loc, "switch starts here");
388638fd1498Szrj     }
388738fd1498Szrj 
388838fd1498Szrj   return saw_error;
388938fd1498Szrj }
389038fd1498Szrj 
389138fd1498Szrj /* Given NAME, an IDENTIFIER_NODE,
389238fd1498Szrj    return the structure (or union or enum) definition for that name.
389338fd1498Szrj    If THISLEVEL_ONLY is nonzero, searches only the current_scope.
389438fd1498Szrj    CODE says which kind of type the caller wants;
389538fd1498Szrj    it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
389638fd1498Szrj    If PLOC is not NULL and this returns non-null, it sets *PLOC to the
389738fd1498Szrj    location where the tag was defined.
389838fd1498Szrj    If the wrong kind of type is found, an error is reported.  */
389938fd1498Szrj 
390038fd1498Szrj static tree
lookup_tag(enum tree_code code,tree name,bool thislevel_only,location_t * ploc)390138fd1498Szrj lookup_tag (enum tree_code code, tree name, bool thislevel_only,
390238fd1498Szrj 	    location_t *ploc)
390338fd1498Szrj {
390438fd1498Szrj   struct c_binding *b = I_TAG_BINDING (name);
390538fd1498Szrj   bool thislevel = false;
390638fd1498Szrj 
390738fd1498Szrj   if (!b || !b->decl)
390838fd1498Szrj     return NULL_TREE;
390938fd1498Szrj 
391038fd1498Szrj   /* We only care about whether it's in this level if
391138fd1498Szrj      thislevel_only was set or it might be a type clash.  */
391238fd1498Szrj   if (thislevel_only || TREE_CODE (b->decl) != code)
391338fd1498Szrj     {
391438fd1498Szrj       /* For our purposes, a tag in the external scope is the same as
391538fd1498Szrj 	 a tag in the file scope.  (Primarily relevant to Objective-C
391638fd1498Szrj 	 and its builtin structure tags, which get pushed before the
391738fd1498Szrj 	 file scope is created.)  */
391838fd1498Szrj       if (B_IN_CURRENT_SCOPE (b)
391938fd1498Szrj 	  || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
392038fd1498Szrj 	thislevel = true;
392138fd1498Szrj     }
392238fd1498Szrj 
392338fd1498Szrj   if (thislevel_only && !thislevel)
392438fd1498Szrj     return NULL_TREE;
392538fd1498Szrj 
392638fd1498Szrj   if (TREE_CODE (b->decl) != code)
392738fd1498Szrj     {
392838fd1498Szrj       /* Definition isn't the kind we were looking for.  */
392938fd1498Szrj       pending_invalid_xref = name;
393038fd1498Szrj       pending_invalid_xref_location = input_location;
393138fd1498Szrj 
393238fd1498Szrj       /* If in the same binding level as a declaration as a tag
393338fd1498Szrj 	 of a different type, this must not be allowed to
393438fd1498Szrj 	 shadow that tag, so give the error immediately.
393538fd1498Szrj 	 (For example, "struct foo; union foo;" is invalid.)  */
393638fd1498Szrj       if (thislevel)
393738fd1498Szrj 	pending_xref_error ();
393838fd1498Szrj     }
393938fd1498Szrj 
394038fd1498Szrj   if (ploc != NULL)
394138fd1498Szrj     *ploc = b->locus;
394238fd1498Szrj 
394338fd1498Szrj   return b->decl;
394438fd1498Szrj }
394538fd1498Szrj 
394638fd1498Szrj /* Return true if a definition exists for NAME with code CODE.  */
394738fd1498Szrj 
394838fd1498Szrj bool
tag_exists_p(enum tree_code code,tree name)394938fd1498Szrj tag_exists_p (enum tree_code code, tree name)
395038fd1498Szrj {
395138fd1498Szrj   struct c_binding *b = I_TAG_BINDING (name);
395238fd1498Szrj 
395338fd1498Szrj   if (b == NULL || b->decl == NULL_TREE)
395438fd1498Szrj     return false;
395538fd1498Szrj   return TREE_CODE (b->decl) == code;
395638fd1498Szrj }
395738fd1498Szrj 
395838fd1498Szrj /* Print an error message now
395938fd1498Szrj    for a recent invalid struct, union or enum cross reference.
396038fd1498Szrj    We don't print them immediately because they are not invalid
396138fd1498Szrj    when used in the `struct foo;' construct for shadowing.  */
396238fd1498Szrj 
396338fd1498Szrj void
pending_xref_error(void)396438fd1498Szrj pending_xref_error (void)
396538fd1498Szrj {
396638fd1498Szrj   if (pending_invalid_xref != NULL_TREE)
396738fd1498Szrj     error_at (pending_invalid_xref_location, "%qE defined as wrong kind of tag",
396838fd1498Szrj 	      pending_invalid_xref);
396938fd1498Szrj   pending_invalid_xref = NULL_TREE;
397038fd1498Szrj }
397138fd1498Szrj 
397238fd1498Szrj 
397338fd1498Szrj /* Look up NAME in the current scope and its superiors
397438fd1498Szrj    in the namespace of variables, functions and typedefs.
397538fd1498Szrj    Return a ..._DECL node of some kind representing its definition,
397638fd1498Szrj    or return NULL_TREE if it is undefined.  */
397738fd1498Szrj 
397838fd1498Szrj tree
lookup_name(tree name)397938fd1498Szrj lookup_name (tree name)
398038fd1498Szrj {
398138fd1498Szrj   struct c_binding *b = I_SYMBOL_BINDING (name);
398238fd1498Szrj   if (b && !b->invisible)
398338fd1498Szrj     {
398438fd1498Szrj       maybe_record_typedef_use (b->decl);
398538fd1498Szrj       return b->decl;
398638fd1498Szrj     }
398738fd1498Szrj   return NULL_TREE;
398838fd1498Szrj }
398938fd1498Szrj 
399038fd1498Szrj /* Similar to `lookup_name' but look only at the indicated scope.  */
399138fd1498Szrj 
399238fd1498Szrj static tree
lookup_name_in_scope(tree name,struct c_scope * scope)399338fd1498Szrj lookup_name_in_scope (tree name, struct c_scope *scope)
399438fd1498Szrj {
399538fd1498Szrj   struct c_binding *b;
399638fd1498Szrj 
399738fd1498Szrj   for (b = I_SYMBOL_BINDING (name); b; b = b->shadowed)
399838fd1498Szrj     if (B_IN_SCOPE (b, scope))
399938fd1498Szrj       return b->decl;
400038fd1498Szrj   return NULL_TREE;
400138fd1498Szrj }
400238fd1498Szrj 
400338fd1498Szrj /* Look for the closest match for NAME within the currently valid
400438fd1498Szrj    scopes.
400538fd1498Szrj 
400638fd1498Szrj    This finds the identifier with the lowest Levenshtein distance to
400738fd1498Szrj    NAME.  If there are multiple candidates with equal minimal distance,
400838fd1498Szrj    the first one found is returned.  Scopes are searched from innermost
400938fd1498Szrj    outwards, and within a scope in reverse order of declaration, thus
401038fd1498Szrj    benefiting candidates "near" to the current scope.
401138fd1498Szrj 
401238fd1498Szrj    The function also looks for similar macro names to NAME, since a
401338fd1498Szrj    misspelled macro name will not be expanded, and hence looks like an
401438fd1498Szrj    identifier to the C frontend.
401538fd1498Szrj 
401638fd1498Szrj    It also looks for start_typename keywords, to detect "singed" vs "signed"
401738fd1498Szrj    typos.
401838fd1498Szrj 
401938fd1498Szrj    Use LOC for any deferred diagnostics.  */
402038fd1498Szrj 
402138fd1498Szrj name_hint
lookup_name_fuzzy(tree name,enum lookup_name_fuzzy_kind kind,location_t loc)402238fd1498Szrj lookup_name_fuzzy (tree name, enum lookup_name_fuzzy_kind kind, location_t loc)
402338fd1498Szrj {
402438fd1498Szrj   gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
402538fd1498Szrj 
402638fd1498Szrj   /* First, try some well-known names in the C standard library, in case
402738fd1498Szrj      the user forgot a #include.  */
402838fd1498Szrj   const char *header_hint
402938fd1498Szrj     = get_c_stdlib_header_for_name (IDENTIFIER_POINTER (name));
403038fd1498Szrj 
403138fd1498Szrj   if (header_hint)
403238fd1498Szrj     return name_hint (NULL,
403338fd1498Szrj 		      new suggest_missing_header (loc,
403438fd1498Szrj 						  IDENTIFIER_POINTER (name),
403538fd1498Szrj 						  header_hint));
403638fd1498Szrj 
403738fd1498Szrj   /* Only suggest names reserved for the implementation if NAME begins
403838fd1498Szrj      with an underscore.  */
403938fd1498Szrj   bool consider_implementation_names = (IDENTIFIER_POINTER (name)[0] == '_');
404038fd1498Szrj 
404138fd1498Szrj   best_match<tree, tree> bm (name);
404238fd1498Szrj 
404338fd1498Szrj   /* Look within currently valid scopes.  */
404438fd1498Szrj   for (c_scope *scope = current_scope; scope; scope = scope->outer)
404538fd1498Szrj     for (c_binding *binding = scope->bindings; binding; binding = binding->prev)
404638fd1498Szrj       {
404738fd1498Szrj 	if (!binding->id || binding->invisible)
404838fd1498Szrj 	  continue;
404938fd1498Szrj 	if (binding->decl == error_mark_node)
405038fd1498Szrj 	  continue;
405138fd1498Szrj 	/* Don't use bindings from implicitly declared functions,
405238fd1498Szrj 	   as they were likely misspellings themselves.  */
405338fd1498Szrj 	if (TREE_CODE (binding->decl) == FUNCTION_DECL)
405438fd1498Szrj 	  if (C_DECL_IMPLICIT (binding->decl))
405538fd1498Szrj 	    continue;
405638fd1498Szrj 	/* Don't suggest names that are reserved for use by the
405738fd1498Szrj 	   implementation, unless NAME began with an underscore.  */
405838fd1498Szrj 	if (!consider_implementation_names)
405938fd1498Szrj 	  {
406038fd1498Szrj 	    const char *suggestion_str = IDENTIFIER_POINTER (binding->id);
406138fd1498Szrj 	    if (name_reserved_for_implementation_p (suggestion_str))
406238fd1498Szrj 	      continue;
406338fd1498Szrj 	  }
406438fd1498Szrj 	switch (kind)
406538fd1498Szrj 	  {
406638fd1498Szrj 	  case FUZZY_LOOKUP_TYPENAME:
406738fd1498Szrj 	    if (TREE_CODE (binding->decl) != TYPE_DECL)
406838fd1498Szrj 	      continue;
406938fd1498Szrj 	    break;
407038fd1498Szrj 
407138fd1498Szrj 	  case FUZZY_LOOKUP_FUNCTION_NAME:
407238fd1498Szrj 	    if (TREE_CODE (binding->decl) != FUNCTION_DECL)
407338fd1498Szrj 	      {
407438fd1498Szrj 		/* Allow function pointers.  */
407538fd1498Szrj 		if ((VAR_P (binding->decl)
407638fd1498Szrj 		     || TREE_CODE (binding->decl) == PARM_DECL)
407738fd1498Szrj 		    && TREE_CODE (TREE_TYPE (binding->decl)) == POINTER_TYPE
407838fd1498Szrj 		    && (TREE_CODE (TREE_TYPE (TREE_TYPE (binding->decl)))
407938fd1498Szrj 			== FUNCTION_TYPE))
408038fd1498Szrj 		  break;
408138fd1498Szrj 		continue;
408238fd1498Szrj 	      }
408338fd1498Szrj 	    break;
408438fd1498Szrj 
408538fd1498Szrj 	  default:
408638fd1498Szrj 	    break;
408738fd1498Szrj 	  }
408838fd1498Szrj 	bm.consider (binding->id);
408938fd1498Szrj       }
409038fd1498Szrj 
409138fd1498Szrj   /* Consider macros: if the user misspelled a macro name e.g. "SOME_MACRO"
409238fd1498Szrj      as:
409338fd1498Szrj        x = SOME_OTHER_MACRO (y);
409438fd1498Szrj      then "SOME_OTHER_MACRO" will survive to the frontend and show up
409538fd1498Szrj      as a misspelled identifier.
409638fd1498Szrj 
409738fd1498Szrj      Use the best distance so far so that a candidate is only set if
409838fd1498Szrj      a macro is better than anything so far.  This allows early rejection
409938fd1498Szrj      (without calculating the edit distance) of macro names that must have
410038fd1498Szrj      distance >= bm.get_best_distance (), and means that we only get a
410138fd1498Szrj      non-NULL result for best_macro_match if it's better than any of
410238fd1498Szrj      the identifiers already checked, which avoids needless creation
410338fd1498Szrj      of identifiers for macro hashnodes.  */
410438fd1498Szrj   best_macro_match bmm (name, bm.get_best_distance (), parse_in);
410538fd1498Szrj   cpp_hashnode *best_macro = bmm.get_best_meaningful_candidate ();
410638fd1498Szrj   /* If a macro is the closest so far to NAME, use it, creating an
410738fd1498Szrj      identifier tree node for it.  */
410838fd1498Szrj   if (best_macro)
410938fd1498Szrj     {
411038fd1498Szrj       const char *id = (const char *)best_macro->ident.str;
411138fd1498Szrj       tree macro_as_identifier
411238fd1498Szrj 	= get_identifier_with_length (id, best_macro->ident.len);
411338fd1498Szrj       bm.set_best_so_far (macro_as_identifier,
411438fd1498Szrj 			  bmm.get_best_distance (),
411538fd1498Szrj 			  bmm.get_best_candidate_length ());
411638fd1498Szrj     }
411738fd1498Szrj 
411838fd1498Szrj   /* Try the "start_typename" keywords to detect
411938fd1498Szrj      "singed" vs "signed" typos.  */
412038fd1498Szrj   if (kind == FUZZY_LOOKUP_TYPENAME)
412138fd1498Szrj     {
412238fd1498Szrj       for (unsigned i = 0; i < num_c_common_reswords; i++)
412338fd1498Szrj 	{
412438fd1498Szrj 	  const c_common_resword *resword = &c_common_reswords[i];
412538fd1498Szrj 	  if (!c_keyword_starts_typename (resword->rid))
412638fd1498Szrj 	    continue;
412738fd1498Szrj 	  tree resword_identifier = ridpointers [resword->rid];
412838fd1498Szrj 	  if (!resword_identifier)
412938fd1498Szrj 	    continue;
413038fd1498Szrj 	  gcc_assert (TREE_CODE (resword_identifier) == IDENTIFIER_NODE);
413138fd1498Szrj 	  bm.consider (resword_identifier);
413238fd1498Szrj 	}
413338fd1498Szrj     }
413438fd1498Szrj 
413538fd1498Szrj   tree best = bm.get_best_meaningful_candidate ();
413638fd1498Szrj   if (best)
413738fd1498Szrj     return name_hint (IDENTIFIER_POINTER (best), NULL);
413838fd1498Szrj   else
413938fd1498Szrj     return name_hint (NULL, NULL);
414038fd1498Szrj }
414138fd1498Szrj 
414238fd1498Szrj 
414338fd1498Szrj /* Create the predefined scalar types of C,
414438fd1498Szrj    and some nodes representing standard constants (0, 1, (void *) 0).
414538fd1498Szrj    Initialize the global scope.
414638fd1498Szrj    Make definitions for built-in primitive functions.  */
414738fd1498Szrj 
414838fd1498Szrj void
c_init_decl_processing(void)414938fd1498Szrj c_init_decl_processing (void)
415038fd1498Szrj {
415138fd1498Szrj   location_t save_loc = input_location;
415238fd1498Szrj 
415338fd1498Szrj   /* Initialize reserved words for parser.  */
415438fd1498Szrj   c_parse_init ();
415538fd1498Szrj 
415638fd1498Szrj   current_function_decl = NULL_TREE;
415738fd1498Szrj 
415838fd1498Szrj   gcc_obstack_init (&parser_obstack);
415938fd1498Szrj 
416038fd1498Szrj   /* Make the externals scope.  */
416138fd1498Szrj   push_scope ();
416238fd1498Szrj   external_scope = current_scope;
416338fd1498Szrj 
416438fd1498Szrj   /* Declarations from c_common_nodes_and_builtins must not be associated
416538fd1498Szrj      with this input file, lest we get differences between using and not
416638fd1498Szrj      using preprocessed headers.  */
416738fd1498Szrj   input_location = BUILTINS_LOCATION;
416838fd1498Szrj 
416938fd1498Szrj   c_common_nodes_and_builtins ();
417038fd1498Szrj 
417138fd1498Szrj   /* In C, comparisons and TRUTH_* expressions have type int.  */
417238fd1498Szrj   truthvalue_type_node = integer_type_node;
417338fd1498Szrj   truthvalue_true_node = integer_one_node;
417438fd1498Szrj   truthvalue_false_node = integer_zero_node;
417538fd1498Szrj 
417638fd1498Szrj   /* Even in C99, which has a real boolean type.  */
417738fd1498Szrj   pushdecl (build_decl (UNKNOWN_LOCATION, TYPE_DECL, get_identifier ("_Bool"),
417838fd1498Szrj 			boolean_type_node));
417938fd1498Szrj 
418038fd1498Szrj   input_location = save_loc;
418138fd1498Szrj 
418238fd1498Szrj   make_fname_decl = c_make_fname_decl;
418338fd1498Szrj   start_fname_decls ();
418438fd1498Szrj }
418538fd1498Szrj 
418638fd1498Szrj /* Create the VAR_DECL at LOC for __FUNCTION__ etc. ID is the name to
418738fd1498Szrj    give the decl, NAME is the initialization string and TYPE_DEP
418838fd1498Szrj    indicates whether NAME depended on the type of the function.  As we
418938fd1498Szrj    don't yet implement delayed emission of static data, we mark the
419038fd1498Szrj    decl as emitted so it is not placed in the output.  Anything using
419138fd1498Szrj    it must therefore pull out the STRING_CST initializer directly.
419238fd1498Szrj    FIXME.  */
419338fd1498Szrj 
419438fd1498Szrj static tree
c_make_fname_decl(location_t loc,tree id,int type_dep)419538fd1498Szrj c_make_fname_decl (location_t loc, tree id, int type_dep)
419638fd1498Szrj {
419738fd1498Szrj   const char *name = fname_as_string (type_dep);
419838fd1498Szrj   tree decl, type, init;
419938fd1498Szrj   size_t length = strlen (name);
420038fd1498Szrj 
420138fd1498Szrj   type = build_array_type (char_type_node,
420238fd1498Szrj 			   build_index_type (size_int (length)));
420338fd1498Szrj   type = c_build_qualified_type (type, TYPE_QUAL_CONST);
420438fd1498Szrj 
420538fd1498Szrj   decl = build_decl (loc, VAR_DECL, id, type);
420638fd1498Szrj 
420738fd1498Szrj   TREE_STATIC (decl) = 1;
420838fd1498Szrj   TREE_READONLY (decl) = 1;
420938fd1498Szrj   DECL_ARTIFICIAL (decl) = 1;
421038fd1498Szrj 
421138fd1498Szrj   init = build_string (length + 1, name);
421238fd1498Szrj   free (CONST_CAST (char *, name));
421338fd1498Szrj   TREE_TYPE (init) = type;
421438fd1498Szrj   DECL_INITIAL (decl) = init;
421538fd1498Szrj 
421638fd1498Szrj   TREE_USED (decl) = 1;
421738fd1498Szrj 
421838fd1498Szrj   if (current_function_decl
421938fd1498Szrj       /* For invalid programs like this:
422038fd1498Szrj 
422138fd1498Szrj          void foo()
422238fd1498Szrj          const char* p = __FUNCTION__;
422338fd1498Szrj 
422438fd1498Szrj 	 the __FUNCTION__ is believed to appear in K&R style function
422538fd1498Szrj 	 parameter declarator.  In that case we still don't have
422638fd1498Szrj 	 function_scope.  */
422738fd1498Szrj       && current_function_scope)
422838fd1498Szrj     {
422938fd1498Szrj       DECL_CONTEXT (decl) = current_function_decl;
423038fd1498Szrj       bind (id, decl, current_function_scope,
423138fd1498Szrj 	    /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION);
423238fd1498Szrj     }
423338fd1498Szrj 
423438fd1498Szrj   finish_decl (decl, loc, init, NULL_TREE, NULL_TREE);
423538fd1498Szrj 
423638fd1498Szrj   return decl;
423738fd1498Szrj }
423838fd1498Szrj 
423938fd1498Szrj tree
c_builtin_function(tree decl)424038fd1498Szrj c_builtin_function (tree decl)
424138fd1498Szrj {
424238fd1498Szrj   tree type = TREE_TYPE (decl);
424338fd1498Szrj   tree   id = DECL_NAME (decl);
424438fd1498Szrj 
424538fd1498Szrj   const char *name = IDENTIFIER_POINTER (id);
424638fd1498Szrj   C_DECL_BUILTIN_PROTOTYPE (decl) = prototype_p (type);
424738fd1498Szrj 
424838fd1498Szrj   /* Should never be called on a symbol with a preexisting meaning.  */
424938fd1498Szrj   gcc_assert (!I_SYMBOL_BINDING (id));
425038fd1498Szrj 
425138fd1498Szrj   bind (id, decl, external_scope, /*invisible=*/true, /*nested=*/false,
425238fd1498Szrj 	UNKNOWN_LOCATION);
425338fd1498Szrj 
425438fd1498Szrj   /* Builtins in the implementation namespace are made visible without
425538fd1498Szrj      needing to be explicitly declared.  See push_file_scope.  */
425638fd1498Szrj   if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1])))
425738fd1498Szrj     {
425838fd1498Szrj       DECL_CHAIN (decl) = visible_builtins;
425938fd1498Szrj       visible_builtins = decl;
426038fd1498Szrj     }
426138fd1498Szrj 
426238fd1498Szrj   return decl;
426338fd1498Szrj }
426438fd1498Szrj 
426538fd1498Szrj tree
c_builtin_function_ext_scope(tree decl)426638fd1498Szrj c_builtin_function_ext_scope (tree decl)
426738fd1498Szrj {
426838fd1498Szrj   tree type = TREE_TYPE (decl);
426938fd1498Szrj   tree   id = DECL_NAME (decl);
427038fd1498Szrj 
427138fd1498Szrj   const char *name = IDENTIFIER_POINTER (id);
427238fd1498Szrj   C_DECL_BUILTIN_PROTOTYPE (decl) = prototype_p (type);
427338fd1498Szrj 
427438fd1498Szrj   if (external_scope)
427538fd1498Szrj     bind (id, decl, external_scope, /*invisible=*/false, /*nested=*/false,
427638fd1498Szrj 	  UNKNOWN_LOCATION);
427738fd1498Szrj 
427838fd1498Szrj   /* Builtins in the implementation namespace are made visible without
427938fd1498Szrj      needing to be explicitly declared.  See push_file_scope.  */
428038fd1498Szrj   if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1])))
428138fd1498Szrj     {
428238fd1498Szrj       DECL_CHAIN (decl) = visible_builtins;
428338fd1498Szrj       visible_builtins = decl;
428438fd1498Szrj     }
428538fd1498Szrj 
428638fd1498Szrj   return decl;
428738fd1498Szrj }
428838fd1498Szrj 
428938fd1498Szrj /* Called when a declaration is seen that contains no names to declare.
429038fd1498Szrj    If its type is a reference to a structure, union or enum inherited
429138fd1498Szrj    from a containing scope, shadow that tag name for the current scope
429238fd1498Szrj    with a forward reference.
429338fd1498Szrj    If its type defines a new named structure or union
429438fd1498Szrj    or defines an enum, it is valid but we need not do anything here.
429538fd1498Szrj    Otherwise, it is an error.  */
429638fd1498Szrj 
429738fd1498Szrj void
shadow_tag(const struct c_declspecs * declspecs)429838fd1498Szrj shadow_tag (const struct c_declspecs *declspecs)
429938fd1498Szrj {
430038fd1498Szrj   shadow_tag_warned (declspecs, 0);
430138fd1498Szrj }
430238fd1498Szrj 
430338fd1498Szrj /* WARNED is 1 if we have done a pedwarn, 2 if we have done a warning,
430438fd1498Szrj    but no pedwarn.  */
430538fd1498Szrj void
shadow_tag_warned(const struct c_declspecs * declspecs,int warned)430638fd1498Szrj shadow_tag_warned (const struct c_declspecs *declspecs, int warned)
430738fd1498Szrj {
430838fd1498Szrj   bool found_tag = false;
430938fd1498Szrj 
431038fd1498Szrj   if (declspecs->type && !declspecs->default_int_p && !declspecs->typedef_p)
431138fd1498Szrj     {
431238fd1498Szrj       tree value = declspecs->type;
431338fd1498Szrj       enum tree_code code = TREE_CODE (value);
431438fd1498Szrj 
431538fd1498Szrj       if (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE)
431638fd1498Szrj 	/* Used to test also that TYPE_SIZE (value) != 0.
431738fd1498Szrj 	   That caused warning for `struct foo;' at top level in the file.  */
431838fd1498Szrj 	{
431938fd1498Szrj 	  tree name = TYPE_NAME (value);
432038fd1498Szrj 	  tree t;
432138fd1498Szrj 
432238fd1498Szrj 	  found_tag = true;
432338fd1498Szrj 
432438fd1498Szrj 	  if (declspecs->restrict_p)
432538fd1498Szrj 	    {
432638fd1498Szrj 	      error ("invalid use of %<restrict%>");
432738fd1498Szrj 	      warned = 1;
432838fd1498Szrj 	    }
432938fd1498Szrj 
433038fd1498Szrj 	  if (name == NULL_TREE)
433138fd1498Szrj 	    {
433238fd1498Szrj 	      if (warned != 1 && code != ENUMERAL_TYPE)
433338fd1498Szrj 		/* Empty unnamed enum OK */
433438fd1498Szrj 		{
433538fd1498Szrj 		  pedwarn (input_location, 0,
433638fd1498Szrj 			   "unnamed struct/union that defines no instances");
433738fd1498Szrj 		  warned = 1;
433838fd1498Szrj 		}
433938fd1498Szrj 	    }
434038fd1498Szrj 	  else if (declspecs->typespec_kind != ctsk_tagdef
434138fd1498Szrj                    && declspecs->typespec_kind != ctsk_tagfirstref
434238fd1498Szrj 		   && declspecs->storage_class != csc_none)
434338fd1498Szrj 	    {
434438fd1498Szrj 	      if (warned != 1)
434538fd1498Szrj 		pedwarn (input_location, 0,
434638fd1498Szrj 			 "empty declaration with storage class specifier "
434738fd1498Szrj 			 "does not redeclare tag");
434838fd1498Szrj 	      warned = 1;
434938fd1498Szrj 	      pending_xref_error ();
435038fd1498Szrj 	    }
435138fd1498Szrj 	  else if (declspecs->typespec_kind != ctsk_tagdef
435238fd1498Szrj                    && declspecs->typespec_kind != ctsk_tagfirstref
435338fd1498Szrj 		   && (declspecs->const_p
435438fd1498Szrj 		       || declspecs->volatile_p
435538fd1498Szrj 		       || declspecs->atomic_p
435638fd1498Szrj 		       || declspecs->restrict_p
435738fd1498Szrj 		       || declspecs->address_space))
435838fd1498Szrj 	    {
435938fd1498Szrj 	      if (warned != 1)
436038fd1498Szrj 		pedwarn (input_location, 0,
436138fd1498Szrj 			 "empty declaration with type qualifier "
436238fd1498Szrj 			  "does not redeclare tag");
436338fd1498Szrj 	      warned = 1;
436438fd1498Szrj 	      pending_xref_error ();
436538fd1498Szrj 	    }
436638fd1498Szrj 	  else if (declspecs->typespec_kind != ctsk_tagdef
436738fd1498Szrj                    && declspecs->typespec_kind != ctsk_tagfirstref
436838fd1498Szrj 		   && declspecs->alignas_p)
436938fd1498Szrj 	    {
437038fd1498Szrj 	      if (warned != 1)
437138fd1498Szrj 		pedwarn (input_location, 0,
437238fd1498Szrj 			 "empty declaration with %<_Alignas%> "
437338fd1498Szrj 			  "does not redeclare tag");
437438fd1498Szrj 	      warned = 1;
437538fd1498Szrj 	      pending_xref_error ();
437638fd1498Szrj 	    }
437738fd1498Szrj 	  else
437838fd1498Szrj 	    {
437938fd1498Szrj 	      pending_invalid_xref = NULL_TREE;
438038fd1498Szrj 	      t = lookup_tag (code, name, true, NULL);
438138fd1498Szrj 
438238fd1498Szrj 	      if (t == NULL_TREE)
438338fd1498Szrj 		{
438438fd1498Szrj 		  t = make_node (code);
438538fd1498Szrj 		  pushtag (input_location, name, t);
438638fd1498Szrj 		}
438738fd1498Szrj 	    }
438838fd1498Szrj 	}
438938fd1498Szrj       else
439038fd1498Szrj 	{
439138fd1498Szrj 	  if (warned != 1 && !in_system_header_at (input_location))
439238fd1498Szrj 	    {
439338fd1498Szrj 	      pedwarn (input_location, 0,
439438fd1498Szrj 		       "useless type name in empty declaration");
439538fd1498Szrj 	      warned = 1;
439638fd1498Szrj 	    }
439738fd1498Szrj 	}
439838fd1498Szrj     }
439938fd1498Szrj   else if (warned != 1 && !in_system_header_at (input_location)
440038fd1498Szrj 	   && declspecs->typedef_p)
440138fd1498Szrj     {
440238fd1498Szrj       pedwarn (input_location, 0, "useless type name in empty declaration");
440338fd1498Szrj       warned = 1;
440438fd1498Szrj     }
440538fd1498Szrj 
440638fd1498Szrj   pending_invalid_xref = NULL_TREE;
440738fd1498Szrj 
440838fd1498Szrj   if (declspecs->inline_p)
440938fd1498Szrj     {
441038fd1498Szrj       error ("%<inline%> in empty declaration");
441138fd1498Szrj       warned = 1;
441238fd1498Szrj     }
441338fd1498Szrj 
441438fd1498Szrj   if (declspecs->noreturn_p)
441538fd1498Szrj     {
441638fd1498Szrj       error ("%<_Noreturn%> in empty declaration");
441738fd1498Szrj       warned = 1;
441838fd1498Szrj     }
441938fd1498Szrj 
442038fd1498Szrj   if (current_scope == file_scope && declspecs->storage_class == csc_auto)
442138fd1498Szrj     {
442238fd1498Szrj       error ("%<auto%> in file-scope empty declaration");
442338fd1498Szrj       warned = 1;
442438fd1498Szrj     }
442538fd1498Szrj 
442638fd1498Szrj   if (current_scope == file_scope && declspecs->storage_class == csc_register)
442738fd1498Szrj     {
442838fd1498Szrj       error ("%<register%> in file-scope empty declaration");
442938fd1498Szrj       warned = 1;
443038fd1498Szrj     }
443138fd1498Szrj 
443238fd1498Szrj   if (!warned && !in_system_header_at (input_location)
443338fd1498Szrj       && declspecs->storage_class != csc_none)
443438fd1498Szrj     {
443538fd1498Szrj       warning (0, "useless storage class specifier in empty declaration");
443638fd1498Szrj       warned = 2;
443738fd1498Szrj     }
443838fd1498Szrj 
443938fd1498Szrj   if (!warned && !in_system_header_at (input_location) && declspecs->thread_p)
444038fd1498Szrj     {
444138fd1498Szrj       warning (0, "useless %qs in empty declaration",
444238fd1498Szrj 	       declspecs->thread_gnu_p ? "__thread" : "_Thread_local");
444338fd1498Szrj       warned = 2;
444438fd1498Szrj     }
444538fd1498Szrj 
444638fd1498Szrj   if (!warned
444738fd1498Szrj       && !in_system_header_at (input_location)
444838fd1498Szrj       && (declspecs->const_p
444938fd1498Szrj 	  || declspecs->volatile_p
445038fd1498Szrj 	  || declspecs->atomic_p
445138fd1498Szrj 	  || declspecs->restrict_p
445238fd1498Szrj 	  || declspecs->address_space))
445338fd1498Szrj     {
445438fd1498Szrj       warning (0, "useless type qualifier in empty declaration");
445538fd1498Szrj       warned = 2;
445638fd1498Szrj     }
445738fd1498Szrj 
445838fd1498Szrj   if (!warned && !in_system_header_at (input_location)
445938fd1498Szrj       && declspecs->alignas_p)
446038fd1498Szrj     {
446138fd1498Szrj       warning (0, "useless %<_Alignas%> in empty declaration");
446238fd1498Szrj       warned = 2;
446338fd1498Szrj     }
446438fd1498Szrj 
446538fd1498Szrj   if (warned != 1)
446638fd1498Szrj     {
446738fd1498Szrj       if (!found_tag)
446838fd1498Szrj 	pedwarn (input_location, 0, "empty declaration");
446938fd1498Szrj     }
447038fd1498Szrj }
447138fd1498Szrj 
447238fd1498Szrj 
447338fd1498Szrj /* Return the qualifiers from SPECS as a bitwise OR of TYPE_QUAL_*
447438fd1498Szrj    bits.  SPECS represents declaration specifiers that the grammar
447538fd1498Szrj    only permits to contain type qualifiers and attributes.  */
447638fd1498Szrj 
447738fd1498Szrj int
quals_from_declspecs(const struct c_declspecs * specs)447838fd1498Szrj quals_from_declspecs (const struct c_declspecs *specs)
447938fd1498Szrj {
448038fd1498Szrj   int quals = ((specs->const_p ? TYPE_QUAL_CONST : 0)
448138fd1498Szrj 	       | (specs->volatile_p ? TYPE_QUAL_VOLATILE : 0)
448238fd1498Szrj 	       | (specs->restrict_p ? TYPE_QUAL_RESTRICT : 0)
448338fd1498Szrj 	       | (specs->atomic_p ? TYPE_QUAL_ATOMIC : 0)
448438fd1498Szrj 	       | (ENCODE_QUAL_ADDR_SPACE (specs->address_space)));
448538fd1498Szrj   gcc_assert (!specs->type
448638fd1498Szrj 	      && !specs->decl_attr
448738fd1498Szrj 	      && specs->typespec_word == cts_none
448838fd1498Szrj 	      && specs->storage_class == csc_none
448938fd1498Szrj 	      && !specs->typedef_p
449038fd1498Szrj 	      && !specs->explicit_signed_p
449138fd1498Szrj 	      && !specs->deprecated_p
449238fd1498Szrj 	      && !specs->long_p
449338fd1498Szrj 	      && !specs->long_long_p
449438fd1498Szrj 	      && !specs->short_p
449538fd1498Szrj 	      && !specs->signed_p
449638fd1498Szrj 	      && !specs->unsigned_p
449738fd1498Szrj 	      && !specs->complex_p
449838fd1498Szrj 	      && !specs->inline_p
449938fd1498Szrj 	      && !specs->noreturn_p
450038fd1498Szrj 	      && !specs->thread_p);
450138fd1498Szrj   return quals;
450238fd1498Szrj }
450338fd1498Szrj 
450438fd1498Szrj /* Construct an array declarator.  LOC is the location of the
450538fd1498Szrj    beginning of the array (usually the opening brace).  EXPR is the
450638fd1498Szrj    expression inside [], or NULL_TREE.  QUALS are the type qualifiers
450738fd1498Szrj    inside the [] (to be applied to the pointer to which a parameter
450838fd1498Szrj    array is converted).  STATIC_P is true if "static" is inside the
450938fd1498Szrj    [], false otherwise.  VLA_UNSPEC_P is true if the array is [*], a
451038fd1498Szrj    VLA of unspecified length which is nevertheless a complete type,
451138fd1498Szrj    false otherwise.  The field for the contained declarator is left to
451238fd1498Szrj    be filled in by set_array_declarator_inner.  */
451338fd1498Szrj 
451438fd1498Szrj struct c_declarator *
build_array_declarator(location_t loc,tree expr,struct c_declspecs * quals,bool static_p,bool vla_unspec_p)451538fd1498Szrj build_array_declarator (location_t loc,
451638fd1498Szrj 			tree expr, struct c_declspecs *quals, bool static_p,
451738fd1498Szrj 			bool vla_unspec_p)
451838fd1498Szrj {
451938fd1498Szrj   struct c_declarator *declarator = XOBNEW (&parser_obstack,
452038fd1498Szrj 					    struct c_declarator);
452138fd1498Szrj   declarator->id_loc = loc;
452238fd1498Szrj   declarator->kind = cdk_array;
452338fd1498Szrj   declarator->declarator = 0;
452438fd1498Szrj   declarator->u.array.dimen = expr;
452538fd1498Szrj   if (quals)
452638fd1498Szrj     {
452738fd1498Szrj       declarator->u.array.attrs = quals->attrs;
452838fd1498Szrj       declarator->u.array.quals = quals_from_declspecs (quals);
452938fd1498Szrj     }
453038fd1498Szrj   else
453138fd1498Szrj     {
453238fd1498Szrj       declarator->u.array.attrs = NULL_TREE;
453338fd1498Szrj       declarator->u.array.quals = 0;
453438fd1498Szrj     }
453538fd1498Szrj   declarator->u.array.static_p = static_p;
453638fd1498Szrj   declarator->u.array.vla_unspec_p = vla_unspec_p;
453738fd1498Szrj   if (static_p || quals != NULL)
453838fd1498Szrj     pedwarn_c90 (loc, OPT_Wpedantic,
453938fd1498Szrj 		 "ISO C90 does not support %<static%> or type "
454038fd1498Szrj 		 "qualifiers in parameter array declarators");
454138fd1498Szrj   if (vla_unspec_p)
454238fd1498Szrj     pedwarn_c90 (loc, OPT_Wpedantic,
454338fd1498Szrj 		 "ISO C90 does not support %<[*]%> array declarators");
454438fd1498Szrj   if (vla_unspec_p)
454538fd1498Szrj     {
454638fd1498Szrj       if (!current_scope->parm_flag)
454738fd1498Szrj 	{
454838fd1498Szrj 	  /* C99 6.7.5.2p4 */
454938fd1498Szrj 	  error_at (loc, "%<[*]%> not allowed in other than "
455038fd1498Szrj 		    "function prototype scope");
455138fd1498Szrj 	  declarator->u.array.vla_unspec_p = false;
455238fd1498Szrj 	  return NULL;
455338fd1498Szrj 	}
455438fd1498Szrj       current_scope->had_vla_unspec = true;
455538fd1498Szrj     }
455638fd1498Szrj   return declarator;
455738fd1498Szrj }
455838fd1498Szrj 
455938fd1498Szrj /* Set the contained declarator of an array declarator.  DECL is the
456038fd1498Szrj    declarator, as constructed by build_array_declarator; INNER is what
456138fd1498Szrj    appears on the left of the [].  */
456238fd1498Szrj 
456338fd1498Szrj struct c_declarator *
set_array_declarator_inner(struct c_declarator * decl,struct c_declarator * inner)456438fd1498Szrj set_array_declarator_inner (struct c_declarator *decl,
456538fd1498Szrj 			    struct c_declarator *inner)
456638fd1498Szrj {
456738fd1498Szrj   decl->declarator = inner;
456838fd1498Szrj   return decl;
456938fd1498Szrj }
457038fd1498Szrj 
457138fd1498Szrj /* INIT is a constructor that forms DECL's initializer.  If the final
457238fd1498Szrj    element initializes a flexible array field, add the size of that
457338fd1498Szrj    initializer to DECL's size.  */
457438fd1498Szrj 
457538fd1498Szrj static void
add_flexible_array_elts_to_size(tree decl,tree init)457638fd1498Szrj add_flexible_array_elts_to_size (tree decl, tree init)
457738fd1498Szrj {
457838fd1498Szrj   tree elt, type;
457938fd1498Szrj 
458038fd1498Szrj   if (vec_safe_is_empty (CONSTRUCTOR_ELTS (init)))
458138fd1498Szrj     return;
458238fd1498Szrj 
458338fd1498Szrj   elt = CONSTRUCTOR_ELTS (init)->last ().value;
458438fd1498Szrj   type = TREE_TYPE (elt);
458538fd1498Szrj   if (TREE_CODE (type) == ARRAY_TYPE
458638fd1498Szrj       && TYPE_SIZE (type) == NULL_TREE
458738fd1498Szrj       && TYPE_DOMAIN (type) != NULL_TREE
458838fd1498Szrj       && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE)
458938fd1498Szrj     {
459038fd1498Szrj       complete_array_type (&type, elt, false);
459138fd1498Szrj       DECL_SIZE (decl)
459238fd1498Szrj 	= size_binop (PLUS_EXPR, DECL_SIZE (decl), TYPE_SIZE (type));
459338fd1498Szrj       DECL_SIZE_UNIT (decl)
459438fd1498Szrj 	= size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl), TYPE_SIZE_UNIT (type));
459538fd1498Szrj     }
459638fd1498Szrj }
459738fd1498Szrj 
459838fd1498Szrj /* Decode a "typename", such as "int **", returning a ..._TYPE node.
459938fd1498Szrj    Set *EXPR, if EXPR not NULL, to any expression to be evaluated
460038fd1498Szrj    before the type name, and set *EXPR_CONST_OPERANDS, if
460138fd1498Szrj    EXPR_CONST_OPERANDS not NULL, to indicate whether the type name may
460238fd1498Szrj    appear in a constant expression.  */
460338fd1498Szrj 
460438fd1498Szrj tree
groktypename(struct c_type_name * type_name,tree * expr,bool * expr_const_operands)460538fd1498Szrj groktypename (struct c_type_name *type_name, tree *expr,
460638fd1498Szrj 	      bool *expr_const_operands)
460738fd1498Szrj {
460838fd1498Szrj   tree type;
460938fd1498Szrj   tree attrs = type_name->specs->attrs;
461038fd1498Szrj 
461138fd1498Szrj   type_name->specs->attrs = NULL_TREE;
461238fd1498Szrj 
461338fd1498Szrj   type = grokdeclarator (type_name->declarator, type_name->specs, TYPENAME,
461438fd1498Szrj 			 false, NULL, &attrs, expr, expr_const_operands,
461538fd1498Szrj 			 DEPRECATED_NORMAL);
461638fd1498Szrj 
461738fd1498Szrj   /* Apply attributes.  */
461838fd1498Szrj   decl_attributes (&type, attrs, 0);
461938fd1498Szrj 
462038fd1498Szrj   return type;
462138fd1498Szrj }
462238fd1498Szrj 
462338fd1498Szrj /* Wrapper for decl_attributes that adds some implicit attributes
462438fd1498Szrj    to VAR_DECLs or FUNCTION_DECLs.  */
462538fd1498Szrj 
462638fd1498Szrj static tree
c_decl_attributes(tree * node,tree attributes,int flags)462738fd1498Szrj c_decl_attributes (tree *node, tree attributes, int flags)
462838fd1498Szrj {
462938fd1498Szrj   /* Add implicit "omp declare target" attribute if requested.  */
463038fd1498Szrj   if (current_omp_declare_target_attribute
463138fd1498Szrj       && ((VAR_P (*node) && is_global_var (*node))
463238fd1498Szrj 	  || TREE_CODE (*node) == FUNCTION_DECL))
463338fd1498Szrj     {
463438fd1498Szrj       if (VAR_P (*node)
463538fd1498Szrj 	  && !lang_hooks.types.omp_mappable_type (TREE_TYPE (*node)))
4636*58e805e6Szrj 	attributes = tree_cons (get_identifier ("omp declare target implicit"),
4637*58e805e6Szrj 				NULL_TREE, attributes);
463838fd1498Szrj       else
463938fd1498Szrj 	attributes = tree_cons (get_identifier ("omp declare target"),
464038fd1498Szrj 				NULL_TREE, attributes);
464138fd1498Szrj     }
464238fd1498Szrj 
464338fd1498Szrj   /* Look up the current declaration with all the attributes merged
464438fd1498Szrj      so far so that attributes on the current declaration that's
464538fd1498Szrj      about to be pushed that conflict with the former can be detected,
464638fd1498Szrj      diagnosed, and rejected as appropriate.  */
464738fd1498Szrj   tree last_decl = lookup_name (DECL_NAME (*node));
464838fd1498Szrj   if (!last_decl)
464938fd1498Szrj     last_decl = lookup_name_in_scope (DECL_NAME (*node), external_scope);
465038fd1498Szrj 
465138fd1498Szrj   return decl_attributes (node, attributes, flags, last_decl);
465238fd1498Szrj }
465338fd1498Szrj 
465438fd1498Szrj 
465538fd1498Szrj /* Decode a declarator in an ordinary declaration or data definition.
465638fd1498Szrj    This is called as soon as the type information and variable name
465738fd1498Szrj    have been parsed, before parsing the initializer if any.
465838fd1498Szrj    Here we create the ..._DECL node, fill in its type,
465938fd1498Szrj    and put it on the list of decls for the current context.
466038fd1498Szrj    The ..._DECL node is returned as the value.
466138fd1498Szrj 
466238fd1498Szrj    Exception: for arrays where the length is not specified,
466338fd1498Szrj    the type is left null, to be filled in by `finish_decl'.
466438fd1498Szrj 
466538fd1498Szrj    Function definitions do not come here; they go to start_function
466638fd1498Szrj    instead.  However, external and forward declarations of functions
466738fd1498Szrj    do go through here.  Structure field declarations are done by
466838fd1498Szrj    grokfield and not through here.  */
466938fd1498Szrj 
467038fd1498Szrj tree
start_decl(struct c_declarator * declarator,struct c_declspecs * declspecs,bool initialized,tree attributes)467138fd1498Szrj start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs,
467238fd1498Szrj 	    bool initialized, tree attributes)
467338fd1498Szrj {
467438fd1498Szrj   tree decl;
467538fd1498Szrj   tree tem;
467638fd1498Szrj   tree expr = NULL_TREE;
467738fd1498Szrj   enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
467838fd1498Szrj 
467938fd1498Szrj   /* An object declared as __attribute__((deprecated)) suppresses
468038fd1498Szrj      warnings of uses of other deprecated items.  */
468138fd1498Szrj   if (lookup_attribute ("deprecated", attributes))
468238fd1498Szrj     deprecated_state = DEPRECATED_SUPPRESS;
468338fd1498Szrj 
468438fd1498Szrj   decl = grokdeclarator (declarator, declspecs,
468538fd1498Szrj 			 NORMAL, initialized, NULL, &attributes, &expr, NULL,
468638fd1498Szrj 			 deprecated_state);
468738fd1498Szrj   if (!decl || decl == error_mark_node)
468838fd1498Szrj     return NULL_TREE;
468938fd1498Szrj 
469038fd1498Szrj   if (expr)
469138fd1498Szrj     add_stmt (fold_convert (void_type_node, expr));
469238fd1498Szrj 
469338fd1498Szrj   if (TREE_CODE (decl) != FUNCTION_DECL && MAIN_NAME_P (DECL_NAME (decl)))
469438fd1498Szrj     warning (OPT_Wmain, "%q+D is usually a function", decl);
469538fd1498Szrj 
469638fd1498Szrj   if (initialized)
469738fd1498Szrj     /* Is it valid for this decl to have an initializer at all?
469838fd1498Szrj        If not, set INITIALIZED to zero, which will indirectly
469938fd1498Szrj        tell 'finish_decl' to ignore the initializer once it is parsed.  */
470038fd1498Szrj     switch (TREE_CODE (decl))
470138fd1498Szrj       {
470238fd1498Szrj       case TYPE_DECL:
470338fd1498Szrj 	error ("typedef %qD is initialized (use __typeof__ instead)", decl);
470438fd1498Szrj 	initialized = false;
470538fd1498Szrj 	break;
470638fd1498Szrj 
470738fd1498Szrj       case FUNCTION_DECL:
470838fd1498Szrj 	error ("function %qD is initialized like a variable", decl);
470938fd1498Szrj 	initialized = false;
471038fd1498Szrj 	break;
471138fd1498Szrj 
471238fd1498Szrj       case PARM_DECL:
471338fd1498Szrj 	/* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE.  */
471438fd1498Szrj 	error ("parameter %qD is initialized", decl);
471538fd1498Szrj 	initialized = false;
471638fd1498Szrj 	break;
471738fd1498Szrj 
471838fd1498Szrj       default:
471938fd1498Szrj 	/* Don't allow initializations for incomplete types except for
472038fd1498Szrj 	   arrays which might be completed by the initialization.  */
472138fd1498Szrj 
472238fd1498Szrj 	/* This can happen if the array size is an undefined macro.
472338fd1498Szrj 	   We already gave a warning, so we don't need another one.  */
472438fd1498Szrj 	if (TREE_TYPE (decl) == error_mark_node)
472538fd1498Szrj 	  initialized = false;
472638fd1498Szrj 	else if (COMPLETE_TYPE_P (TREE_TYPE (decl)))
472738fd1498Szrj 	  {
472838fd1498Szrj 	    /* A complete type is ok if size is fixed.  */
472938fd1498Szrj 
473038fd1498Szrj 	    if (TREE_CODE (TYPE_SIZE (TREE_TYPE (decl))) != INTEGER_CST
473138fd1498Szrj 		|| C_DECL_VARIABLE_SIZE (decl))
473238fd1498Szrj 	      {
473338fd1498Szrj 		error ("variable-sized object may not be initialized");
473438fd1498Szrj 		initialized = false;
473538fd1498Szrj 	      }
473638fd1498Szrj 	  }
473738fd1498Szrj 	else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE)
473838fd1498Szrj 	  {
473938fd1498Szrj 	    error ("variable %qD has initializer but incomplete type", decl);
474038fd1498Szrj 	    initialized = false;
474138fd1498Szrj 	  }
474238fd1498Szrj 	else if (C_DECL_VARIABLE_SIZE (decl))
474338fd1498Szrj 	  {
474438fd1498Szrj 	    /* Although C99 is unclear about whether incomplete arrays
474538fd1498Szrj 	       of VLAs themselves count as VLAs, it does not make
474638fd1498Szrj 	       sense to permit them to be initialized given that
474738fd1498Szrj 	       ordinary VLAs may not be initialized.  */
474838fd1498Szrj 	    error ("variable-sized object may not be initialized");
474938fd1498Szrj 	    initialized = false;
475038fd1498Szrj 	  }
475138fd1498Szrj       }
475238fd1498Szrj 
475338fd1498Szrj   if (initialized)
475438fd1498Szrj     {
475538fd1498Szrj       if (current_scope == file_scope)
475638fd1498Szrj 	TREE_STATIC (decl) = 1;
475738fd1498Szrj 
475838fd1498Szrj       /* Tell 'pushdecl' this is an initialized decl
475938fd1498Szrj 	 even though we don't yet have the initializer expression.
476038fd1498Szrj 	 Also tell 'finish_decl' it may store the real initializer.  */
476138fd1498Szrj       DECL_INITIAL (decl) = error_mark_node;
476238fd1498Szrj     }
476338fd1498Szrj 
476438fd1498Szrj   /* If this is a function declaration, write a record describing it to the
476538fd1498Szrj      prototypes file (if requested).  */
476638fd1498Szrj 
476738fd1498Szrj   if (TREE_CODE (decl) == FUNCTION_DECL)
476838fd1498Szrj     gen_aux_info_record (decl, 0, 0, prototype_p (TREE_TYPE (decl)));
476938fd1498Szrj 
477038fd1498Szrj   /* ANSI specifies that a tentative definition which is not merged with
477138fd1498Szrj      a non-tentative definition behaves exactly like a definition with an
477238fd1498Szrj      initializer equal to zero.  (Section 3.7.2)
477338fd1498Szrj 
477438fd1498Szrj      -fno-common gives strict ANSI behavior, though this tends to break
477538fd1498Szrj      a large body of code that grew up without this rule.
477638fd1498Szrj 
477738fd1498Szrj      Thread-local variables are never common, since there's no entrenched
477838fd1498Szrj      body of code to break, and it allows more efficient variable references
477938fd1498Szrj      in the presence of dynamic linking.  */
478038fd1498Szrj 
478138fd1498Szrj   if (VAR_P (decl)
478238fd1498Szrj       && !initialized
478338fd1498Szrj       && TREE_PUBLIC (decl)
478438fd1498Szrj       && !DECL_THREAD_LOCAL_P (decl)
478538fd1498Szrj       && !flag_no_common)
478638fd1498Szrj     DECL_COMMON (decl) = 1;
478738fd1498Szrj 
478838fd1498Szrj   /* Set attributes here so if duplicate decl, will have proper attributes.  */
478938fd1498Szrj   c_decl_attributes (&decl, attributes, 0);
479038fd1498Szrj 
479138fd1498Szrj   /* Handle gnu_inline attribute.  */
479238fd1498Szrj   if (declspecs->inline_p
479338fd1498Szrj       && !flag_gnu89_inline
479438fd1498Szrj       && TREE_CODE (decl) == FUNCTION_DECL
479538fd1498Szrj       && (lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (decl))
479638fd1498Szrj 	  || current_function_decl))
479738fd1498Szrj     {
479838fd1498Szrj       if (declspecs->storage_class == csc_auto && current_scope != file_scope)
479938fd1498Szrj 	;
480038fd1498Szrj       else if (declspecs->storage_class != csc_static)
480138fd1498Szrj 	DECL_EXTERNAL (decl) = !DECL_EXTERNAL (decl);
480238fd1498Szrj     }
480338fd1498Szrj 
480438fd1498Szrj   if (TREE_CODE (decl) == FUNCTION_DECL
480538fd1498Szrj       && targetm.calls.promote_prototypes (TREE_TYPE (decl)))
480638fd1498Szrj     {
480738fd1498Szrj       struct c_declarator *ce = declarator;
480838fd1498Szrj 
480938fd1498Szrj       if (ce->kind == cdk_pointer)
481038fd1498Szrj 	ce = declarator->declarator;
481138fd1498Szrj       if (ce->kind == cdk_function)
481238fd1498Szrj 	{
481338fd1498Szrj 	  tree args = ce->u.arg_info->parms;
481438fd1498Szrj 	  for (; args; args = DECL_CHAIN (args))
481538fd1498Szrj 	    {
481638fd1498Szrj 	      tree type = TREE_TYPE (args);
481738fd1498Szrj 	      if (type && INTEGRAL_TYPE_P (type)
481838fd1498Szrj 		  && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
481938fd1498Szrj 		DECL_ARG_TYPE (args) = c_type_promotes_to (type);
482038fd1498Szrj 	    }
482138fd1498Szrj 	}
482238fd1498Szrj     }
482338fd1498Szrj 
482438fd1498Szrj   if (TREE_CODE (decl) == FUNCTION_DECL
482538fd1498Szrj       && DECL_DECLARED_INLINE_P (decl)
482638fd1498Szrj       && DECL_UNINLINABLE (decl)
482738fd1498Szrj       && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
482838fd1498Szrj     warning (OPT_Wattributes, "inline function %q+D given attribute noinline",
482938fd1498Szrj 	     decl);
483038fd1498Szrj 
483138fd1498Szrj   /* C99 6.7.4p3: An inline definition of a function with external
483238fd1498Szrj      linkage shall not contain a definition of a modifiable object
483338fd1498Szrj      with static storage duration...  */
483438fd1498Szrj   if (VAR_P (decl)
483538fd1498Szrj       && current_scope != file_scope
483638fd1498Szrj       && TREE_STATIC (decl)
483738fd1498Szrj       && !TREE_READONLY (decl)
483838fd1498Szrj       && DECL_DECLARED_INLINE_P (current_function_decl)
483938fd1498Szrj       && DECL_EXTERNAL (current_function_decl))
484038fd1498Szrj     record_inline_static (input_location, current_function_decl,
484138fd1498Szrj 			  decl, csi_modifiable);
484238fd1498Szrj 
484338fd1498Szrj   if (c_dialect_objc ()
484438fd1498Szrj       && VAR_OR_FUNCTION_DECL_P (decl))
484538fd1498Szrj       objc_check_global_decl (decl);
484638fd1498Szrj 
484738fd1498Szrj   /* Add this decl to the current scope.
484838fd1498Szrj      TEM may equal DECL or it may be a previous decl of the same name.  */
484938fd1498Szrj   tem = pushdecl (decl);
485038fd1498Szrj 
485138fd1498Szrj   if (initialized && DECL_EXTERNAL (tem))
485238fd1498Szrj     {
485338fd1498Szrj       DECL_EXTERNAL (tem) = 0;
485438fd1498Szrj       TREE_STATIC (tem) = 1;
485538fd1498Szrj     }
485638fd1498Szrj 
485738fd1498Szrj   return tem;
485838fd1498Szrj }
485938fd1498Szrj 
486038fd1498Szrj /* Subroutine of finish_decl. TYPE is the type of an uninitialized object
486138fd1498Szrj    DECL or the non-array element type if DECL is an uninitialized array.
486238fd1498Szrj    If that type has a const member, diagnose this. */
486338fd1498Szrj 
486438fd1498Szrj static void
diagnose_uninitialized_cst_member(tree decl,tree type)486538fd1498Szrj diagnose_uninitialized_cst_member (tree decl, tree type)
486638fd1498Szrj {
486738fd1498Szrj   tree field;
486838fd1498Szrj   for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
486938fd1498Szrj     {
487038fd1498Szrj       tree field_type;
487138fd1498Szrj       if (TREE_CODE (field) != FIELD_DECL)
487238fd1498Szrj 	continue;
487338fd1498Szrj       field_type = strip_array_types (TREE_TYPE (field));
487438fd1498Szrj 
487538fd1498Szrj       if (TYPE_QUALS (field_type) & TYPE_QUAL_CONST)
487638fd1498Szrj       	{
487738fd1498Szrj 	  warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
487838fd1498Szrj 	  	      "uninitialized const member in %qT is invalid in C++",
487938fd1498Szrj 		      strip_array_types (TREE_TYPE (decl)));
488038fd1498Szrj 	  inform (DECL_SOURCE_LOCATION (field), "%qD should be initialized", field);
488138fd1498Szrj 	}
488238fd1498Szrj 
488338fd1498Szrj       if (RECORD_OR_UNION_TYPE_P (field_type))
488438fd1498Szrj 	diagnose_uninitialized_cst_member (decl, field_type);
488538fd1498Szrj     }
488638fd1498Szrj }
488738fd1498Szrj 
488838fd1498Szrj /* Finish processing of a declaration;
488938fd1498Szrj    install its initial value.
489038fd1498Szrj    If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
489138fd1498Szrj    If the length of an array type is not known before,
489238fd1498Szrj    it must be determined now, from the initial value, or it is an error.
489338fd1498Szrj 
489438fd1498Szrj    INIT_LOC is the location of the initial value.  */
489538fd1498Szrj 
489638fd1498Szrj void
finish_decl(tree decl,location_t init_loc,tree init,tree origtype,tree asmspec_tree)489738fd1498Szrj finish_decl (tree decl, location_t init_loc, tree init,
489838fd1498Szrj 	     tree origtype, tree asmspec_tree)
489938fd1498Szrj {
490038fd1498Szrj   tree type;
490138fd1498Szrj   bool was_incomplete = (DECL_SIZE (decl) == NULL_TREE);
490238fd1498Szrj   const char *asmspec = 0;
490338fd1498Szrj 
490438fd1498Szrj   /* If a name was specified, get the string.  */
490538fd1498Szrj   if (VAR_OR_FUNCTION_DECL_P (decl)
490638fd1498Szrj       && DECL_FILE_SCOPE_P (decl))
490738fd1498Szrj     asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
490838fd1498Szrj   if (asmspec_tree)
490938fd1498Szrj     asmspec = TREE_STRING_POINTER (asmspec_tree);
491038fd1498Szrj 
491138fd1498Szrj   if (VAR_P (decl)
491238fd1498Szrj       && TREE_STATIC (decl)
491338fd1498Szrj       && global_bindings_p ())
491438fd1498Szrj     /* So decl is a global variable. Record the types it uses
491538fd1498Szrj        so that we can decide later to emit debug info for them.  */
491638fd1498Szrj     record_types_used_by_current_var_decl (decl);
491738fd1498Szrj 
491838fd1498Szrj   /* If `start_decl' didn't like having an initialization, ignore it now.  */
491938fd1498Szrj   if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE)
492038fd1498Szrj     init = NULL_TREE;
492138fd1498Szrj 
492238fd1498Szrj   /* Don't crash if parm is initialized.  */
492338fd1498Szrj   if (TREE_CODE (decl) == PARM_DECL)
492438fd1498Szrj     init = NULL_TREE;
492538fd1498Szrj 
492638fd1498Szrj   if (init)
492738fd1498Szrj     store_init_value (init_loc, decl, init, origtype);
492838fd1498Szrj 
492938fd1498Szrj   if (c_dialect_objc () && (VAR_OR_FUNCTION_DECL_P (decl)
493038fd1498Szrj 			    || TREE_CODE (decl) == FIELD_DECL))
493138fd1498Szrj     objc_check_decl (decl);
493238fd1498Szrj 
493338fd1498Szrj   type = TREE_TYPE (decl);
493438fd1498Szrj 
493538fd1498Szrj   /* Deduce size of array from initialization, if not already known.  */
493638fd1498Szrj   if (TREE_CODE (type) == ARRAY_TYPE
493738fd1498Szrj       && TYPE_DOMAIN (type) == NULL_TREE
493838fd1498Szrj       && TREE_CODE (decl) != TYPE_DECL)
493938fd1498Szrj     {
494038fd1498Szrj       bool do_default
494138fd1498Szrj 	= (TREE_STATIC (decl)
494238fd1498Szrj 	   /* Even if pedantic, an external linkage array
494338fd1498Szrj 	      may have incomplete type at first.  */
494438fd1498Szrj 	   ? pedantic && !TREE_PUBLIC (decl)
494538fd1498Szrj 	   : !DECL_EXTERNAL (decl));
494638fd1498Szrj       int failure
494738fd1498Szrj 	= complete_array_type (&TREE_TYPE (decl), DECL_INITIAL (decl),
494838fd1498Szrj 			       do_default);
494938fd1498Szrj 
495038fd1498Szrj       /* Get the completed type made by complete_array_type.  */
495138fd1498Szrj       type = TREE_TYPE (decl);
495238fd1498Szrj 
495338fd1498Szrj       switch (failure)
495438fd1498Szrj 	{
495538fd1498Szrj 	case 1:
495638fd1498Szrj 	  error ("initializer fails to determine size of %q+D", decl);
495738fd1498Szrj 	  break;
495838fd1498Szrj 
495938fd1498Szrj 	case 2:
496038fd1498Szrj 	  if (do_default)
496138fd1498Szrj 	    error ("array size missing in %q+D", decl);
496238fd1498Szrj 	  /* If a `static' var's size isn't known,
496338fd1498Szrj 	     make it extern as well as static, so it does not get
496438fd1498Szrj 	     allocated.
496538fd1498Szrj 	     If it is not `static', then do not mark extern;
496638fd1498Szrj 	     finish_incomplete_decl will give it a default size
496738fd1498Szrj 	     and it will get allocated.  */
496838fd1498Szrj 	  else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
496938fd1498Szrj 	    DECL_EXTERNAL (decl) = 1;
497038fd1498Szrj 	  break;
497138fd1498Szrj 
497238fd1498Szrj 	case 3:
497338fd1498Szrj 	  error ("zero or negative size array %q+D", decl);
497438fd1498Szrj 	  break;
497538fd1498Szrj 
497638fd1498Szrj 	case 0:
497738fd1498Szrj 	  /* For global variables, update the copy of the type that
497838fd1498Szrj 	     exists in the binding.  */
497938fd1498Szrj 	  if (TREE_PUBLIC (decl))
498038fd1498Szrj 	    {
498138fd1498Szrj 	      struct c_binding *b_ext = I_SYMBOL_BINDING (DECL_NAME (decl));
498238fd1498Szrj 	      while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext))
498338fd1498Szrj 		b_ext = b_ext->shadowed;
498438fd1498Szrj 	      if (b_ext && TREE_CODE (decl) == TREE_CODE (b_ext->decl))
498538fd1498Szrj 		{
498638fd1498Szrj 		  if (b_ext->u.type && comptypes (b_ext->u.type, type))
498738fd1498Szrj 		    b_ext->u.type = composite_type (b_ext->u.type, type);
498838fd1498Szrj 		  else
498938fd1498Szrj 		    b_ext->u.type = type;
499038fd1498Szrj 		}
499138fd1498Szrj 	    }
499238fd1498Szrj 	  break;
499338fd1498Szrj 
499438fd1498Szrj 	default:
499538fd1498Szrj 	  gcc_unreachable ();
499638fd1498Szrj 	}
499738fd1498Szrj 
499838fd1498Szrj       if (DECL_INITIAL (decl))
499938fd1498Szrj 	TREE_TYPE (DECL_INITIAL (decl)) = type;
500038fd1498Szrj 
500138fd1498Szrj       relayout_decl (decl);
500238fd1498Szrj     }
500338fd1498Szrj 
500438fd1498Szrj   if (VAR_P (decl))
500538fd1498Szrj     {
500638fd1498Szrj       if (init && TREE_CODE (init) == CONSTRUCTOR)
500738fd1498Szrj 	add_flexible_array_elts_to_size (decl, init);
500838fd1498Szrj 
500938fd1498Szrj       if (DECL_SIZE (decl) == NULL_TREE && TREE_TYPE (decl) != error_mark_node
501038fd1498Szrj 	  && COMPLETE_TYPE_P (TREE_TYPE (decl)))
501138fd1498Szrj 	layout_decl (decl, 0);
501238fd1498Szrj 
501338fd1498Szrj       if (DECL_SIZE (decl) == NULL_TREE
501438fd1498Szrj 	  /* Don't give an error if we already gave one earlier.  */
501538fd1498Szrj 	  && TREE_TYPE (decl) != error_mark_node
501638fd1498Szrj 	  && (TREE_STATIC (decl)
501738fd1498Szrj 	      /* A static variable with an incomplete type
501838fd1498Szrj 		 is an error if it is initialized.
501938fd1498Szrj 		 Also if it is not file scope.
502038fd1498Szrj 		 Otherwise, let it through, but if it is not `extern'
502138fd1498Szrj 		 then it may cause an error message later.  */
502238fd1498Szrj 	      ? (DECL_INITIAL (decl) != NULL_TREE
502338fd1498Szrj 		 || !DECL_FILE_SCOPE_P (decl))
502438fd1498Szrj 	      /* An automatic variable with an incomplete type
502538fd1498Szrj 		 is an error.  */
502638fd1498Szrj 	      : !DECL_EXTERNAL (decl)))
502738fd1498Szrj 	 {
502838fd1498Szrj 	   error ("storage size of %q+D isn%'t known", decl);
502938fd1498Szrj 	   TREE_TYPE (decl) = error_mark_node;
503038fd1498Szrj 	 }
503138fd1498Szrj 
503238fd1498Szrj       if ((RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl))
503338fd1498Szrj 	  || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
503438fd1498Szrj 	  && DECL_SIZE (decl) == NULL_TREE
503538fd1498Szrj 	  && TREE_STATIC (decl))
503638fd1498Szrj 	incomplete_record_decls.safe_push (decl);
503738fd1498Szrj 
503838fd1498Szrj       if (is_global_var (decl) && DECL_SIZE (decl) != NULL_TREE)
503938fd1498Szrj 	{
504038fd1498Szrj 	  if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
504138fd1498Szrj 	    constant_expression_warning (DECL_SIZE (decl));
504238fd1498Szrj 	  else
504338fd1498Szrj 	    {
504438fd1498Szrj 	      error ("storage size of %q+D isn%'t constant", decl);
504538fd1498Szrj 	      TREE_TYPE (decl) = error_mark_node;
504638fd1498Szrj 	    }
504738fd1498Szrj 	}
504838fd1498Szrj 
504938fd1498Szrj       if (TREE_USED (type))
505038fd1498Szrj 	{
505138fd1498Szrj 	  TREE_USED (decl) = 1;
505238fd1498Szrj 	  DECL_READ_P (decl) = 1;
505338fd1498Szrj 	}
505438fd1498Szrj     }
505538fd1498Szrj 
505638fd1498Szrj   /* If this is a function and an assembler name is specified, reset DECL_RTL
505738fd1498Szrj      so we can give it its new name.  Also, update builtin_decl if it
505838fd1498Szrj      was a normal built-in.  */
505938fd1498Szrj   if (TREE_CODE (decl) == FUNCTION_DECL && asmspec)
506038fd1498Szrj     {
506138fd1498Szrj       if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL)
506238fd1498Szrj 	set_builtin_user_assembler_name (decl, asmspec);
506338fd1498Szrj       set_user_assembler_name (decl, asmspec);
506438fd1498Szrj     }
506538fd1498Szrj 
506638fd1498Szrj   /* If #pragma weak was used, mark the decl weak now.  */
506738fd1498Szrj   maybe_apply_pragma_weak (decl);
506838fd1498Szrj 
506938fd1498Szrj   /* Output the assembler code and/or RTL code for variables and functions,
507038fd1498Szrj      unless the type is an undefined structure or union.
507138fd1498Szrj      If not, it will get done when the type is completed.  */
507238fd1498Szrj 
507338fd1498Szrj   if (VAR_OR_FUNCTION_DECL_P (decl))
507438fd1498Szrj     {
507538fd1498Szrj       /* Determine the ELF visibility.  */
507638fd1498Szrj       if (TREE_PUBLIC (decl))
507738fd1498Szrj 	c_determine_visibility (decl);
507838fd1498Szrj 
507938fd1498Szrj       /* This is a no-op in c-lang.c or something real in objc-act.c.  */
508038fd1498Szrj       if (c_dialect_objc ())
508138fd1498Szrj 	objc_check_decl (decl);
508238fd1498Szrj 
508338fd1498Szrj       if (asmspec)
508438fd1498Szrj 	{
508538fd1498Szrj 	  /* If this is not a static variable, issue a warning.
508638fd1498Szrj 	     It doesn't make any sense to give an ASMSPEC for an
508738fd1498Szrj 	     ordinary, non-register local variable.  Historically,
508838fd1498Szrj 	     GCC has accepted -- but ignored -- the ASMSPEC in
508938fd1498Szrj 	     this case.  */
509038fd1498Szrj 	  if (!DECL_FILE_SCOPE_P (decl)
509138fd1498Szrj 	      && VAR_P (decl)
509238fd1498Szrj 	      && !C_DECL_REGISTER (decl)
509338fd1498Szrj 	      && !TREE_STATIC (decl))
509438fd1498Szrj 	    warning (0, "ignoring asm-specifier for non-static local "
509538fd1498Szrj 		     "variable %q+D", decl);
509638fd1498Szrj 	  else
509738fd1498Szrj 	    set_user_assembler_name (decl, asmspec);
509838fd1498Szrj 	}
509938fd1498Szrj 
510038fd1498Szrj       if (DECL_FILE_SCOPE_P (decl))
510138fd1498Szrj 	{
510238fd1498Szrj 	  if (DECL_INITIAL (decl) == NULL_TREE
510338fd1498Szrj 	      || DECL_INITIAL (decl) == error_mark_node)
510438fd1498Szrj 	    /* Don't output anything
510538fd1498Szrj 	       when a tentative file-scope definition is seen.
510638fd1498Szrj 	       But at end of compilation, do output code for them.  */
510738fd1498Szrj 	    DECL_DEFER_OUTPUT (decl) = 1;
510838fd1498Szrj 	  if (asmspec && VAR_P (decl) && C_DECL_REGISTER (decl))
510938fd1498Szrj 	    DECL_HARD_REGISTER (decl) = 1;
511038fd1498Szrj 	  rest_of_decl_compilation (decl, true, 0);
511138fd1498Szrj 	}
511238fd1498Szrj       else
511338fd1498Szrj 	{
511438fd1498Szrj 	  /* In conjunction with an ASMSPEC, the `register'
511538fd1498Szrj 	     keyword indicates that we should place the variable
511638fd1498Szrj 	     in a particular register.  */
511738fd1498Szrj 	  if (asmspec && C_DECL_REGISTER (decl))
511838fd1498Szrj 	    {
511938fd1498Szrj 	      DECL_HARD_REGISTER (decl) = 1;
512038fd1498Szrj 	      /* This cannot be done for a structure with volatile
512138fd1498Szrj 		 fields, on which DECL_REGISTER will have been
512238fd1498Szrj 		 reset.  */
512338fd1498Szrj 	      if (!DECL_REGISTER (decl))
512438fd1498Szrj 		error ("cannot put object with volatile field into register");
512538fd1498Szrj 	    }
512638fd1498Szrj 
512738fd1498Szrj 	  if (TREE_CODE (decl) != FUNCTION_DECL)
512838fd1498Szrj 	    {
512938fd1498Szrj 	      /* If we're building a variable sized type, and we might be
513038fd1498Szrj 		 reachable other than via the top of the current binding
513138fd1498Szrj 		 level, then create a new BIND_EXPR so that we deallocate
513238fd1498Szrj 		 the object at the right time.  */
513338fd1498Szrj 	      /* Note that DECL_SIZE can be null due to errors.  */
513438fd1498Szrj 	      if (DECL_SIZE (decl)
513538fd1498Szrj 		  && !TREE_CONSTANT (DECL_SIZE (decl))
513638fd1498Szrj 		  && STATEMENT_LIST_HAS_LABEL (cur_stmt_list))
513738fd1498Szrj 		{
513838fd1498Szrj 		  tree bind;
513938fd1498Szrj 		  bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
514038fd1498Szrj 		  TREE_SIDE_EFFECTS (bind) = 1;
514138fd1498Szrj 		  add_stmt (bind);
514238fd1498Szrj 		  BIND_EXPR_BODY (bind) = push_stmt_list ();
514338fd1498Szrj 		}
514438fd1498Szrj 	      add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl),
514538fd1498Szrj 				    DECL_EXPR, decl));
514638fd1498Szrj 	    }
514738fd1498Szrj 	}
514838fd1498Szrj 
514938fd1498Szrj 
515038fd1498Szrj       if (!DECL_FILE_SCOPE_P (decl))
515138fd1498Szrj 	{
515238fd1498Szrj 	  /* Recompute the RTL of a local array now
515338fd1498Szrj 	     if it used to be an incomplete type.  */
515438fd1498Szrj 	  if (was_incomplete && !is_global_var (decl))
515538fd1498Szrj 	    {
515638fd1498Szrj 	      /* If we used it already as memory, it must stay in memory.  */
515738fd1498Szrj 	      TREE_ADDRESSABLE (decl) = TREE_USED (decl);
515838fd1498Szrj 	      /* If it's still incomplete now, no init will save it.  */
515938fd1498Szrj 	      if (DECL_SIZE (decl) == NULL_TREE)
516038fd1498Szrj 		DECL_INITIAL (decl) = NULL_TREE;
516138fd1498Szrj 	    }
516238fd1498Szrj 	}
516338fd1498Szrj     }
516438fd1498Szrj 
516538fd1498Szrj   if (TREE_CODE (decl) == TYPE_DECL)
516638fd1498Szrj     {
516738fd1498Szrj       if (!DECL_FILE_SCOPE_P (decl)
516838fd1498Szrj 	  && variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
516938fd1498Szrj 	add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
517038fd1498Szrj 
517138fd1498Szrj       rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl), 0);
517238fd1498Szrj     }
517338fd1498Szrj 
517438fd1498Szrj   /* Install a cleanup (aka destructor) if one was given.  */
517538fd1498Szrj   if (VAR_P (decl) && !TREE_STATIC (decl))
517638fd1498Szrj     {
517738fd1498Szrj       tree attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl));
517838fd1498Szrj       if (attr)
517938fd1498Szrj 	{
518038fd1498Szrj 	  tree cleanup_id = TREE_VALUE (TREE_VALUE (attr));
518138fd1498Szrj 	  tree cleanup_decl = lookup_name (cleanup_id);
518238fd1498Szrj 	  tree cleanup;
518338fd1498Szrj 	  vec<tree, va_gc> *v;
518438fd1498Szrj 
518538fd1498Szrj 	  /* Build "cleanup(&decl)" for the destructor.  */
518638fd1498Szrj 	  cleanup = build_unary_op (input_location, ADDR_EXPR, decl, false);
518738fd1498Szrj 	  vec_alloc (v, 1);
518838fd1498Szrj 	  v->quick_push (cleanup);
518938fd1498Szrj 	  cleanup = c_build_function_call_vec (DECL_SOURCE_LOCATION (decl),
519038fd1498Szrj 					       vNULL, cleanup_decl, v, NULL);
519138fd1498Szrj 	  vec_free (v);
519238fd1498Szrj 
519338fd1498Szrj 	  /* Don't warn about decl unused; the cleanup uses it.  */
519438fd1498Szrj 	  TREE_USED (decl) = 1;
519538fd1498Szrj 	  TREE_USED (cleanup_decl) = 1;
519638fd1498Szrj 	  DECL_READ_P (decl) = 1;
519738fd1498Szrj 
519838fd1498Szrj 	  push_cleanup (decl, cleanup, false);
519938fd1498Szrj 	}
520038fd1498Szrj     }
520138fd1498Szrj 
520238fd1498Szrj   if (warn_cxx_compat
520338fd1498Szrj       && VAR_P (decl)
520438fd1498Szrj       && !DECL_EXTERNAL (decl)
520538fd1498Szrj       && DECL_INITIAL (decl) == NULL_TREE)
520638fd1498Szrj     {
520738fd1498Szrj       type = strip_array_types (type);
520838fd1498Szrj       if (TREE_READONLY (decl))
520938fd1498Szrj 	warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
521038fd1498Szrj 		    "uninitialized const %qD is invalid in C++", decl);
521138fd1498Szrj       else if (RECORD_OR_UNION_TYPE_P (type)
521238fd1498Szrj 	       && C_TYPE_FIELDS_READONLY (type))
521338fd1498Szrj 	diagnose_uninitialized_cst_member (decl, type);
521438fd1498Szrj     }
521538fd1498Szrj 
5216*58e805e6Szrj   if (flag_openmp
5217*58e805e6Szrj       && VAR_P (decl)
5218*58e805e6Szrj       && lookup_attribute ("omp declare target implicit",
5219*58e805e6Szrj 			   DECL_ATTRIBUTES (decl)))
5220*58e805e6Szrj     {
5221*58e805e6Szrj       DECL_ATTRIBUTES (decl)
5222*58e805e6Szrj 	= remove_attribute ("omp declare target implicit",
5223*58e805e6Szrj 			    DECL_ATTRIBUTES (decl));
5224*58e805e6Szrj       if (!lang_hooks.types.omp_mappable_type (TREE_TYPE (decl)))
5225*58e805e6Szrj 	error ("%q+D in declare target directive does not have mappable type",
5226*58e805e6Szrj 	       decl);
5227*58e805e6Szrj       else if (!lookup_attribute ("omp declare target",
5228*58e805e6Szrj 				  DECL_ATTRIBUTES (decl))
5229*58e805e6Szrj 	       && !lookup_attribute ("omp declare target link",
5230*58e805e6Szrj 				     DECL_ATTRIBUTES (decl)))
5231*58e805e6Szrj 	DECL_ATTRIBUTES (decl)
5232*58e805e6Szrj 	  = tree_cons (get_identifier ("omp declare target"),
5233*58e805e6Szrj 		       NULL_TREE, DECL_ATTRIBUTES (decl));
5234*58e805e6Szrj     }
5235*58e805e6Szrj 
523638fd1498Szrj   invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl);
523738fd1498Szrj }
523838fd1498Szrj 
523938fd1498Szrj /* Given a parsed parameter declaration, decode it into a PARM_DECL.
524038fd1498Szrj    EXPR is NULL or a pointer to an expression that needs to be
524138fd1498Szrj    evaluated for the side effects of array size expressions in the
524238fd1498Szrj    parameters.  */
524338fd1498Szrj 
524438fd1498Szrj tree
grokparm(const struct c_parm * parm,tree * expr)524538fd1498Szrj grokparm (const struct c_parm *parm, tree *expr)
524638fd1498Szrj {
524738fd1498Szrj   tree attrs = parm->attrs;
524838fd1498Szrj   tree decl = grokdeclarator (parm->declarator, parm->specs, PARM, false,
524938fd1498Szrj 			      NULL, &attrs, expr, NULL, DEPRECATED_NORMAL);
525038fd1498Szrj 
525138fd1498Szrj   decl_attributes (&decl, attrs, 0);
525238fd1498Szrj 
525338fd1498Szrj   return decl;
525438fd1498Szrj }
525538fd1498Szrj 
525638fd1498Szrj /* Given a parsed parameter declaration, decode it into a PARM_DECL
525738fd1498Szrj    and push that on the current scope.  EXPR is a pointer to an
525838fd1498Szrj    expression that needs to be evaluated for the side effects of array
525938fd1498Szrj    size expressions in the parameters.  */
526038fd1498Szrj 
526138fd1498Szrj void
push_parm_decl(const struct c_parm * parm,tree * expr)526238fd1498Szrj push_parm_decl (const struct c_parm *parm, tree *expr)
526338fd1498Szrj {
526438fd1498Szrj   tree attrs = parm->attrs;
526538fd1498Szrj   tree decl;
526638fd1498Szrj 
526738fd1498Szrj   decl = grokdeclarator (parm->declarator, parm->specs, PARM, false, NULL,
526838fd1498Szrj 			 &attrs, expr, NULL, DEPRECATED_NORMAL);
526938fd1498Szrj   if (decl && DECL_P (decl))
527038fd1498Szrj     DECL_SOURCE_LOCATION (decl) = parm->loc;
527138fd1498Szrj   decl_attributes (&decl, attrs, 0);
527238fd1498Szrj 
527338fd1498Szrj   decl = pushdecl (decl);
527438fd1498Szrj 
527538fd1498Szrj   finish_decl (decl, input_location, NULL_TREE, NULL_TREE, NULL_TREE);
527638fd1498Szrj }
527738fd1498Szrj 
527838fd1498Szrj /* Mark all the parameter declarations to date as forward decls.
527938fd1498Szrj    Also diagnose use of this extension.  */
528038fd1498Szrj 
528138fd1498Szrj void
mark_forward_parm_decls(void)528238fd1498Szrj mark_forward_parm_decls (void)
528338fd1498Szrj {
528438fd1498Szrj   struct c_binding *b;
528538fd1498Szrj 
528638fd1498Szrj   if (pedantic && !current_scope->warned_forward_parm_decls)
528738fd1498Szrj     {
528838fd1498Szrj       pedwarn (input_location, OPT_Wpedantic,
528938fd1498Szrj 	       "ISO C forbids forward parameter declarations");
529038fd1498Szrj       current_scope->warned_forward_parm_decls = true;
529138fd1498Szrj     }
529238fd1498Szrj 
529338fd1498Szrj   for (b = current_scope->bindings; b; b = b->prev)
529438fd1498Szrj     if (TREE_CODE (b->decl) == PARM_DECL)
529538fd1498Szrj       TREE_ASM_WRITTEN (b->decl) = 1;
529638fd1498Szrj }
529738fd1498Szrj 
529838fd1498Szrj /* Build a COMPOUND_LITERAL_EXPR.  TYPE is the type given in the compound
529938fd1498Szrj    literal, which may be an incomplete array type completed by the
530038fd1498Szrj    initializer; INIT is a CONSTRUCTOR at LOC that initializes the compound
530138fd1498Szrj    literal.  NON_CONST is true if the initializers contain something
530238fd1498Szrj    that cannot occur in a constant expression.  If ALIGNAS_ALIGN is nonzero,
530338fd1498Szrj    it is the (valid) alignment for this compound literal, as specified
530438fd1498Szrj    with _Alignas.  */
530538fd1498Szrj 
530638fd1498Szrj tree
build_compound_literal(location_t loc,tree type,tree init,bool non_const,unsigned int alignas_align)530738fd1498Szrj build_compound_literal (location_t loc, tree type, tree init, bool non_const,
530838fd1498Szrj 			unsigned int alignas_align)
530938fd1498Szrj {
531038fd1498Szrj   /* We do not use start_decl here because we have a type, not a declarator;
531138fd1498Szrj      and do not use finish_decl because the decl should be stored inside
531238fd1498Szrj      the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_EXPR.  */
531338fd1498Szrj   tree decl;
531438fd1498Szrj   tree complit;
531538fd1498Szrj   tree stmt;
531638fd1498Szrj 
531738fd1498Szrj   if (type == error_mark_node
531838fd1498Szrj       || init == error_mark_node)
531938fd1498Szrj     return error_mark_node;
532038fd1498Szrj 
532138fd1498Szrj   decl = build_decl (loc, VAR_DECL, NULL_TREE, type);
532238fd1498Szrj   DECL_EXTERNAL (decl) = 0;
532338fd1498Szrj   TREE_PUBLIC (decl) = 0;
532438fd1498Szrj   TREE_STATIC (decl) = (current_scope == file_scope);
532538fd1498Szrj   DECL_CONTEXT (decl) = current_function_decl;
532638fd1498Szrj   TREE_USED (decl) = 1;
532738fd1498Szrj   DECL_READ_P (decl) = 1;
532838fd1498Szrj   DECL_ARTIFICIAL (decl) = 1;
532938fd1498Szrj   DECL_IGNORED_P (decl) = 1;
533038fd1498Szrj   TREE_TYPE (decl) = type;
533138fd1498Szrj   c_apply_type_quals_to_decl (TYPE_QUALS (strip_array_types (type)), decl);
533238fd1498Szrj   if (alignas_align)
533338fd1498Szrj     {
533438fd1498Szrj       SET_DECL_ALIGN (decl, alignas_align * BITS_PER_UNIT);
533538fd1498Szrj       DECL_USER_ALIGN (decl) = 1;
533638fd1498Szrj     }
533738fd1498Szrj   store_init_value (loc, decl, init, NULL_TREE);
533838fd1498Szrj 
533938fd1498Szrj   if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type))
534038fd1498Szrj     {
534138fd1498Szrj       int failure = complete_array_type (&TREE_TYPE (decl),
534238fd1498Szrj 					 DECL_INITIAL (decl), true);
534338fd1498Szrj       /* If complete_array_type returns 3, it means that the
534438fd1498Szrj          initial value of the compound literal is empty.  Allow it.  */
534538fd1498Szrj       gcc_assert (failure == 0 || failure == 3);
534638fd1498Szrj 
534738fd1498Szrj       type = TREE_TYPE (decl);
534838fd1498Szrj       TREE_TYPE (DECL_INITIAL (decl)) = type;
534938fd1498Szrj     }
535038fd1498Szrj 
535138fd1498Szrj   if (type == error_mark_node || !COMPLETE_TYPE_P (type))
535238fd1498Szrj     {
535338fd1498Szrj       c_incomplete_type_error (loc, NULL_TREE, type);
535438fd1498Szrj       return error_mark_node;
535538fd1498Szrj     }
535638fd1498Szrj 
535738fd1498Szrj   stmt = build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl);
535838fd1498Szrj   complit = build1 (COMPOUND_LITERAL_EXPR, type, stmt);
535938fd1498Szrj   TREE_SIDE_EFFECTS (complit) = 1;
536038fd1498Szrj 
536138fd1498Szrj   layout_decl (decl, 0);
536238fd1498Szrj 
536338fd1498Szrj   if (TREE_STATIC (decl))
536438fd1498Szrj     {
536538fd1498Szrj       /* This decl needs a name for the assembler output.  */
536638fd1498Szrj       set_compound_literal_name (decl);
536738fd1498Szrj       DECL_DEFER_OUTPUT (decl) = 1;
536838fd1498Szrj       DECL_COMDAT (decl) = 1;
536938fd1498Szrj       pushdecl (decl);
537038fd1498Szrj       rest_of_decl_compilation (decl, 1, 0);
537138fd1498Szrj     }
537238fd1498Szrj 
537338fd1498Szrj   if (non_const)
537438fd1498Szrj     {
537538fd1498Szrj       complit = build2 (C_MAYBE_CONST_EXPR, type, NULL, complit);
537638fd1498Szrj       C_MAYBE_CONST_EXPR_NON_CONST (complit) = 1;
537738fd1498Szrj     }
537838fd1498Szrj 
537938fd1498Szrj   return complit;
538038fd1498Szrj }
538138fd1498Szrj 
538238fd1498Szrj /* Check the type of a compound literal.  Here we just check that it
538338fd1498Szrj    is valid for C++.  */
538438fd1498Szrj 
538538fd1498Szrj void
check_compound_literal_type(location_t loc,struct c_type_name * type_name)538638fd1498Szrj check_compound_literal_type (location_t loc, struct c_type_name *type_name)
538738fd1498Szrj {
538838fd1498Szrj   if (warn_cxx_compat
538938fd1498Szrj       && (type_name->specs->typespec_kind == ctsk_tagdef
539038fd1498Szrj           || type_name->specs->typespec_kind == ctsk_tagfirstref))
539138fd1498Szrj     warning_at (loc, OPT_Wc___compat,
539238fd1498Szrj 		"defining a type in a compound literal is invalid in C++");
539338fd1498Szrj }
539438fd1498Szrj 
539538fd1498Szrj /* Determine whether TYPE is a structure with a flexible array member,
539638fd1498Szrj    or a union containing such a structure (possibly recursively).  */
539738fd1498Szrj 
539838fd1498Szrj static bool
flexible_array_type_p(tree type)539938fd1498Szrj flexible_array_type_p (tree type)
540038fd1498Szrj {
540138fd1498Szrj   tree x;
540238fd1498Szrj   switch (TREE_CODE (type))
540338fd1498Szrj     {
540438fd1498Szrj     case RECORD_TYPE:
540538fd1498Szrj       x = TYPE_FIELDS (type);
540638fd1498Szrj       if (x == NULL_TREE)
540738fd1498Szrj 	return false;
540838fd1498Szrj       while (DECL_CHAIN (x) != NULL_TREE)
540938fd1498Szrj 	x = DECL_CHAIN (x);
541038fd1498Szrj       if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
541138fd1498Szrj 	  && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
541238fd1498Szrj 	  && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE
541338fd1498Szrj 	  && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE)
541438fd1498Szrj 	return true;
541538fd1498Szrj       return false;
541638fd1498Szrj     case UNION_TYPE:
541738fd1498Szrj       for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x))
541838fd1498Szrj 	{
541938fd1498Szrj 	  if (flexible_array_type_p (TREE_TYPE (x)))
542038fd1498Szrj 	    return true;
542138fd1498Szrj 	}
542238fd1498Szrj       return false;
542338fd1498Szrj     default:
542438fd1498Szrj     return false;
542538fd1498Szrj   }
542638fd1498Szrj }
542738fd1498Szrj 
542838fd1498Szrj /* Performs sanity checks on the TYPE and WIDTH of the bit-field NAME,
542938fd1498Szrj    replacing with appropriate values if they are invalid.  */
543038fd1498Szrj 
543138fd1498Szrj static void
check_bitfield_type_and_width(location_t loc,tree * type,tree * width,tree orig_name)543238fd1498Szrj check_bitfield_type_and_width (location_t loc, tree *type, tree *width,
543338fd1498Szrj 			       tree orig_name)
543438fd1498Szrj {
543538fd1498Szrj   tree type_mv;
543638fd1498Szrj   unsigned int max_width;
543738fd1498Szrj   unsigned HOST_WIDE_INT w;
543838fd1498Szrj   const char *name = (orig_name
543938fd1498Szrj 		      ? identifier_to_locale (IDENTIFIER_POINTER (orig_name))
544038fd1498Szrj 		      : _("<anonymous>"));
544138fd1498Szrj 
544238fd1498Szrj   /* Detect and ignore out of range field width and process valid
544338fd1498Szrj      field widths.  */
544438fd1498Szrj   if (!INTEGRAL_TYPE_P (TREE_TYPE (*width)))
544538fd1498Szrj     {
544638fd1498Szrj       error_at (loc, "bit-field %qs width not an integer constant", name);
544738fd1498Szrj       *width = integer_one_node;
544838fd1498Szrj     }
544938fd1498Szrj   else
545038fd1498Szrj     {
545138fd1498Szrj       if (TREE_CODE (*width) != INTEGER_CST)
545238fd1498Szrj 	{
545338fd1498Szrj 	  *width = c_fully_fold (*width, false, NULL);
545438fd1498Szrj 	  if (TREE_CODE (*width) == INTEGER_CST)
545538fd1498Szrj 	    pedwarn (loc, OPT_Wpedantic,
545638fd1498Szrj 		     "bit-field %qs width not an integer constant expression",
545738fd1498Szrj 		     name);
545838fd1498Szrj 	}
545938fd1498Szrj       if (TREE_CODE (*width) != INTEGER_CST)
546038fd1498Szrj 	{
546138fd1498Szrj 	  error_at (loc, "bit-field %qs width not an integer constant", name);
546238fd1498Szrj 	  *width = integer_one_node;
546338fd1498Szrj 	}
546438fd1498Szrj       constant_expression_warning (*width);
546538fd1498Szrj       if (tree_int_cst_sgn (*width) < 0)
546638fd1498Szrj 	{
546738fd1498Szrj 	  error_at (loc, "negative width in bit-field %qs", name);
546838fd1498Szrj 	  *width = integer_one_node;
546938fd1498Szrj 	}
547038fd1498Szrj       else if (integer_zerop (*width) && orig_name)
547138fd1498Szrj 	{
547238fd1498Szrj 	  error_at (loc, "zero width for bit-field %qs", name);
547338fd1498Szrj 	  *width = integer_one_node;
547438fd1498Szrj 	}
547538fd1498Szrj     }
547638fd1498Szrj 
547738fd1498Szrj   /* Detect invalid bit-field type.  */
547838fd1498Szrj   if (TREE_CODE (*type) != INTEGER_TYPE
547938fd1498Szrj       && TREE_CODE (*type) != BOOLEAN_TYPE
548038fd1498Szrj       && TREE_CODE (*type) != ENUMERAL_TYPE)
548138fd1498Szrj     {
548238fd1498Szrj       error_at (loc, "bit-field %qs has invalid type", name);
548338fd1498Szrj       *type = unsigned_type_node;
548438fd1498Szrj     }
548538fd1498Szrj 
548638fd1498Szrj   if (TYPE_WARN_IF_NOT_ALIGN (*type))
548738fd1498Szrj     {
548838fd1498Szrj       error_at (loc, "cannot declare bit-field %qs with %<warn_if_not_aligned%> type",
548938fd1498Szrj 		name);
549038fd1498Szrj       *type = unsigned_type_node;
549138fd1498Szrj     }
549238fd1498Szrj 
549338fd1498Szrj   type_mv = TYPE_MAIN_VARIANT (*type);
549438fd1498Szrj   if (!in_system_header_at (input_location)
549538fd1498Szrj       && type_mv != integer_type_node
549638fd1498Szrj       && type_mv != unsigned_type_node
549738fd1498Szrj       && type_mv != boolean_type_node)
549838fd1498Szrj     pedwarn_c90 (loc, OPT_Wpedantic,
549938fd1498Szrj 		 "type of bit-field %qs is a GCC extension", name);
550038fd1498Szrj 
550138fd1498Szrj   max_width = TYPE_PRECISION (*type);
550238fd1498Szrj 
550338fd1498Szrj   if (compare_tree_int (*width, max_width) > 0)
550438fd1498Szrj     {
550538fd1498Szrj       error_at (loc, "width of %qs exceeds its type", name);
550638fd1498Szrj       w = max_width;
550738fd1498Szrj       *width = build_int_cst (integer_type_node, w);
550838fd1498Szrj     }
550938fd1498Szrj   else
551038fd1498Szrj     w = tree_to_uhwi (*width);
551138fd1498Szrj 
551238fd1498Szrj   if (TREE_CODE (*type) == ENUMERAL_TYPE)
551338fd1498Szrj     {
551438fd1498Szrj       struct lang_type *lt = TYPE_LANG_SPECIFIC (*type);
551538fd1498Szrj       if (!lt
551638fd1498Szrj 	  || w < tree_int_cst_min_precision (lt->enum_min, TYPE_SIGN (*type))
551738fd1498Szrj 	  || w < tree_int_cst_min_precision (lt->enum_max, TYPE_SIGN (*type)))
551838fd1498Szrj 	warning_at (loc, 0, "%qs is narrower than values of its type", name);
551938fd1498Szrj     }
552038fd1498Szrj }
552138fd1498Szrj 
552238fd1498Szrj 
552338fd1498Szrj 
552438fd1498Szrj /* Print warning about variable length array if necessary.  */
552538fd1498Szrj 
552638fd1498Szrj static void
warn_variable_length_array(tree name,tree size)552738fd1498Szrj warn_variable_length_array (tree name, tree size)
552838fd1498Szrj {
552938fd1498Szrj   if (TREE_CONSTANT (size))
553038fd1498Szrj     {
553138fd1498Szrj       if (name)
553238fd1498Szrj 	pedwarn_c90 (input_location, OPT_Wvla,
553338fd1498Szrj 		     "ISO C90 forbids array %qE whose size "
553438fd1498Szrj 		     "can%'t be evaluated", name);
553538fd1498Szrj       else
553638fd1498Szrj 	pedwarn_c90 (input_location, OPT_Wvla, "ISO C90 forbids array "
553738fd1498Szrj 		     "whose size can%'t be evaluated");
553838fd1498Szrj     }
553938fd1498Szrj   else
554038fd1498Szrj     {
554138fd1498Szrj       if (name)
554238fd1498Szrj 	pedwarn_c90 (input_location, OPT_Wvla,
554338fd1498Szrj 		     "ISO C90 forbids variable length array %qE", name);
554438fd1498Szrj       else
554538fd1498Szrj 	pedwarn_c90 (input_location, OPT_Wvla, "ISO C90 forbids variable "
554638fd1498Szrj 		     "length array");
554738fd1498Szrj     }
554838fd1498Szrj }
554938fd1498Szrj 
555038fd1498Szrj /* Print warning about defaulting to int if necessary.  */
555138fd1498Szrj 
555238fd1498Szrj static void
warn_defaults_to(location_t location,int opt,const char * gmsgid,...)555338fd1498Szrj warn_defaults_to (location_t location, int opt, const char *gmsgid, ...)
555438fd1498Szrj {
555538fd1498Szrj   diagnostic_info diagnostic;
555638fd1498Szrj   va_list ap;
555738fd1498Szrj   rich_location richloc (line_table, location);
555838fd1498Szrj 
555938fd1498Szrj   va_start (ap, gmsgid);
556038fd1498Szrj   diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
556138fd1498Szrj                        flag_isoc99 ? DK_PEDWARN : DK_WARNING);
556238fd1498Szrj   diagnostic.option_index = opt;
556338fd1498Szrj   diagnostic_report_diagnostic (global_dc, &diagnostic);
556438fd1498Szrj   va_end (ap);
556538fd1498Szrj }
556638fd1498Szrj 
556738fd1498Szrj /* Returns the smallest location != UNKNOWN_LOCATION in LOCATIONS,
556838fd1498Szrj    considering only those c_declspec_words found in LIST, which
556938fd1498Szrj    must be terminated by cdw_number_of_elements.  */
557038fd1498Szrj 
557138fd1498Szrj static location_t
smallest_type_quals_location(const location_t * locations,const c_declspec_word * list)557238fd1498Szrj smallest_type_quals_location (const location_t *locations,
557338fd1498Szrj 			      const c_declspec_word *list)
557438fd1498Szrj {
557538fd1498Szrj   location_t loc = UNKNOWN_LOCATION;
557638fd1498Szrj   while (*list != cdw_number_of_elements)
557738fd1498Szrj     {
557838fd1498Szrj       location_t newloc = locations[*list];
557938fd1498Szrj       if (loc == UNKNOWN_LOCATION
558038fd1498Szrj 	  || (newloc != UNKNOWN_LOCATION && newloc < loc))
558138fd1498Szrj 	loc = newloc;
558238fd1498Szrj       list++;
558338fd1498Szrj     }
558438fd1498Szrj 
558538fd1498Szrj   return loc;
558638fd1498Szrj }
558738fd1498Szrj 
558838fd1498Szrj /* Given declspecs and a declarator,
558938fd1498Szrj    determine the name and type of the object declared
559038fd1498Szrj    and construct a ..._DECL node for it.
559138fd1498Szrj    (In one case we can return a ..._TYPE node instead.
559238fd1498Szrj     For invalid input we sometimes return NULL_TREE.)
559338fd1498Szrj 
559438fd1498Szrj    DECLSPECS is a c_declspecs structure for the declaration specifiers.
559538fd1498Szrj 
559638fd1498Szrj    DECL_CONTEXT says which syntactic context this declaration is in:
559738fd1498Szrj      NORMAL for most contexts.  Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
559838fd1498Szrj      FUNCDEF for a function definition.  Like NORMAL but a few different
559938fd1498Szrj       error messages in each case.  Return value may be zero meaning
560038fd1498Szrj       this definition is too screwy to try to parse.
560138fd1498Szrj      PARM for a parameter declaration (either within a function prototype
560238fd1498Szrj       or before a function body).  Make a PARM_DECL, or return void_type_node.
560338fd1498Szrj      TYPENAME if for a typename (in a cast or sizeof).
560438fd1498Szrj       Don't make a DECL node; just return the ..._TYPE node.
560538fd1498Szrj      FIELD for a struct or union field; make a FIELD_DECL.
560638fd1498Szrj    INITIALIZED is true if the decl has an initializer.
560738fd1498Szrj    WIDTH is non-NULL for bit-fields, and is a pointer to an INTEGER_CST node
560838fd1498Szrj    representing the width of the bit-field.
560938fd1498Szrj    DECL_ATTRS points to the list of attributes that should be added to this
561038fd1498Szrj      decl.  Any nested attributes that belong on the decl itself will be
561138fd1498Szrj      added to this list.
561238fd1498Szrj    If EXPR is not NULL, any expressions that need to be evaluated as
561338fd1498Szrj      part of evaluating variably modified types will be stored in *EXPR.
561438fd1498Szrj    If EXPR_CONST_OPERANDS is not NULL, *EXPR_CONST_OPERANDS will be
561538fd1498Szrj      set to indicate whether operands in *EXPR can be used in constant
561638fd1498Szrj      expressions.
561738fd1498Szrj    DEPRECATED_STATE is a deprecated_states value indicating whether
561838fd1498Szrj    deprecation warnings should be suppressed.
561938fd1498Szrj 
562038fd1498Szrj    In the TYPENAME case, DECLARATOR is really an absolute declarator.
562138fd1498Szrj    It may also be so in the PARM case, for a prototype where the
562238fd1498Szrj    argument type is specified but not the name.
562338fd1498Szrj 
562438fd1498Szrj    This function is where the complicated C meanings of `static'
562538fd1498Szrj    and `extern' are interpreted.  */
562638fd1498Szrj 
562738fd1498Szrj static tree
grokdeclarator(const struct c_declarator * declarator,struct c_declspecs * declspecs,enum decl_context decl_context,bool initialized,tree * width,tree * decl_attrs,tree * expr,bool * expr_const_operands,enum deprecated_states deprecated_state)562838fd1498Szrj grokdeclarator (const struct c_declarator *declarator,
562938fd1498Szrj 		struct c_declspecs *declspecs,
563038fd1498Szrj 		enum decl_context decl_context, bool initialized, tree *width,
563138fd1498Szrj 		tree *decl_attrs, tree *expr, bool *expr_const_operands,
563238fd1498Szrj 		enum deprecated_states deprecated_state)
563338fd1498Szrj {
563438fd1498Szrj   tree type = declspecs->type;
563538fd1498Szrj   bool threadp = declspecs->thread_p;
563638fd1498Szrj   enum c_storage_class storage_class = declspecs->storage_class;
563738fd1498Szrj   int constp;
563838fd1498Szrj   int restrictp;
563938fd1498Szrj   int volatilep;
564038fd1498Szrj   int atomicp;
564138fd1498Szrj   int type_quals = TYPE_UNQUALIFIED;
564238fd1498Szrj   tree name = NULL_TREE;
564338fd1498Szrj   bool funcdef_flag = false;
564438fd1498Szrj   bool funcdef_syntax = false;
564538fd1498Szrj   bool size_varies = false;
564638fd1498Szrj   tree decl_attr = declspecs->decl_attr;
564738fd1498Szrj   int array_ptr_quals = TYPE_UNQUALIFIED;
564838fd1498Szrj   tree array_ptr_attrs = NULL_TREE;
564938fd1498Szrj   bool array_parm_static = false;
565038fd1498Szrj   bool array_parm_vla_unspec_p = false;
565138fd1498Szrj   tree returned_attrs = NULL_TREE;
565238fd1498Szrj   bool bitfield = width != NULL;
565338fd1498Szrj   tree element_type;
565438fd1498Szrj   tree orig_qual_type = NULL;
565538fd1498Szrj   size_t orig_qual_indirect = 0;
565638fd1498Szrj   struct c_arg_info *arg_info = 0;
565738fd1498Szrj   addr_space_t as1, as2, address_space;
565838fd1498Szrj   location_t loc = UNKNOWN_LOCATION;
565938fd1498Szrj   tree expr_dummy;
566038fd1498Szrj   bool expr_const_operands_dummy;
566138fd1498Szrj   enum c_declarator_kind first_non_attr_kind;
566238fd1498Szrj   unsigned int alignas_align = 0;
566338fd1498Szrj 
566438fd1498Szrj   if (TREE_CODE (type) == ERROR_MARK)
566538fd1498Szrj     return error_mark_node;
566638fd1498Szrj   if (expr == NULL)
566738fd1498Szrj     {
566838fd1498Szrj       expr = &expr_dummy;
566938fd1498Szrj       expr_dummy = NULL_TREE;
567038fd1498Szrj     }
567138fd1498Szrj   if (expr_const_operands == NULL)
567238fd1498Szrj     expr_const_operands = &expr_const_operands_dummy;
567338fd1498Szrj 
567438fd1498Szrj   if (declspecs->expr)
567538fd1498Szrj     {
567638fd1498Szrj       if (*expr)
567738fd1498Szrj 	*expr = build2 (COMPOUND_EXPR, TREE_TYPE (declspecs->expr), *expr,
567838fd1498Szrj 			declspecs->expr);
567938fd1498Szrj       else
568038fd1498Szrj 	*expr = declspecs->expr;
568138fd1498Szrj     }
568238fd1498Szrj   *expr_const_operands = declspecs->expr_const_operands;
568338fd1498Szrj 
568438fd1498Szrj   if (decl_context == FUNCDEF)
568538fd1498Szrj     funcdef_flag = true, decl_context = NORMAL;
568638fd1498Szrj 
568738fd1498Szrj   /* Look inside a declarator for the name being declared
568838fd1498Szrj      and get it as an IDENTIFIER_NODE, for an error message.  */
568938fd1498Szrj   {
569038fd1498Szrj     const struct c_declarator *decl = declarator;
569138fd1498Szrj 
569238fd1498Szrj     first_non_attr_kind = cdk_attrs;
569338fd1498Szrj     while (decl)
569438fd1498Szrj       switch (decl->kind)
569538fd1498Szrj 	{
569638fd1498Szrj 	case cdk_array:
569738fd1498Szrj 	  loc = decl->id_loc;
569838fd1498Szrj 	  /* FALL THRU.  */
569938fd1498Szrj 
570038fd1498Szrj 	case cdk_function:
570138fd1498Szrj 	case cdk_pointer:
570238fd1498Szrj 	  funcdef_syntax = (decl->kind == cdk_function);
570338fd1498Szrj 	  if (first_non_attr_kind == cdk_attrs)
570438fd1498Szrj 	    first_non_attr_kind = decl->kind;
570538fd1498Szrj 	  decl = decl->declarator;
570638fd1498Szrj 	  break;
570738fd1498Szrj 
570838fd1498Szrj 	case cdk_attrs:
570938fd1498Szrj 	  decl = decl->declarator;
571038fd1498Szrj 	  break;
571138fd1498Szrj 
571238fd1498Szrj 	case cdk_id:
571338fd1498Szrj 	  loc = decl->id_loc;
571438fd1498Szrj 	  if (decl->u.id)
571538fd1498Szrj 	    name = decl->u.id;
571638fd1498Szrj 	  if (first_non_attr_kind == cdk_attrs)
571738fd1498Szrj 	    first_non_attr_kind = decl->kind;
571838fd1498Szrj 	  decl = 0;
571938fd1498Szrj 	  break;
572038fd1498Szrj 
572138fd1498Szrj 	default:
572238fd1498Szrj 	  gcc_unreachable ();
572338fd1498Szrj 	}
572438fd1498Szrj     if (name == NULL_TREE)
572538fd1498Szrj       {
572638fd1498Szrj 	gcc_assert (decl_context == PARM
572738fd1498Szrj 		    || decl_context == TYPENAME
572838fd1498Szrj 		    || (decl_context == FIELD
572938fd1498Szrj 			&& declarator->kind == cdk_id));
573038fd1498Szrj 	gcc_assert (!initialized);
573138fd1498Szrj       }
573238fd1498Szrj   }
573338fd1498Szrj 
573438fd1498Szrj   /* A function definition's declarator must have the form of
573538fd1498Szrj      a function declarator.  */
573638fd1498Szrj 
573738fd1498Szrj   if (funcdef_flag && !funcdef_syntax)
573838fd1498Szrj     return NULL_TREE;
573938fd1498Szrj 
574038fd1498Szrj   /* If this looks like a function definition, make it one,
574138fd1498Szrj      even if it occurs where parms are expected.
574238fd1498Szrj      Then store_parm_decls will reject it and not use it as a parm.  */
574338fd1498Szrj   if (decl_context == NORMAL && !funcdef_flag && current_scope->parm_flag)
574438fd1498Szrj     decl_context = PARM;
574538fd1498Szrj 
574638fd1498Szrj   if (declspecs->deprecated_p && deprecated_state != DEPRECATED_SUPPRESS)
574738fd1498Szrj     warn_deprecated_use (declspecs->type, declspecs->decl_attr);
574838fd1498Szrj 
574938fd1498Szrj   if ((decl_context == NORMAL || decl_context == FIELD)
575038fd1498Szrj       && current_scope == file_scope
575138fd1498Szrj       && variably_modified_type_p (type, NULL_TREE))
575238fd1498Szrj     {
575338fd1498Szrj       if (name)
575438fd1498Szrj 	error_at (loc, "variably modified %qE at file scope", name);
575538fd1498Szrj       else
575638fd1498Szrj 	error_at (loc, "variably modified field at file scope");
575738fd1498Szrj       type = integer_type_node;
575838fd1498Szrj     }
575938fd1498Szrj 
576038fd1498Szrj   size_varies = C_TYPE_VARIABLE_SIZE (type) != 0;
576138fd1498Szrj 
576238fd1498Szrj   /* Diagnose defaulting to "int".  */
576338fd1498Szrj 
576438fd1498Szrj   if (declspecs->default_int_p && !in_system_header_at (input_location))
576538fd1498Szrj     {
576638fd1498Szrj       /* Issue a warning if this is an ISO C 99 program or if
576738fd1498Szrj 	 -Wreturn-type and this is a function, or if -Wimplicit;
576838fd1498Szrj 	 prefer the former warning since it is more explicit.  */
576938fd1498Szrj       if ((warn_implicit_int || warn_return_type || flag_isoc99)
577038fd1498Szrj 	  && funcdef_flag)
577138fd1498Szrj 	warn_about_return_type = 1;
577238fd1498Szrj       else
577338fd1498Szrj 	{
577438fd1498Szrj 	  if (name)
577538fd1498Szrj 	    warn_defaults_to (loc, OPT_Wimplicit_int,
577638fd1498Szrj 			      "type defaults to %<int%> in declaration "
577738fd1498Szrj 			      "of %qE", name);
577838fd1498Szrj 	  else
577938fd1498Szrj 	    warn_defaults_to (loc, OPT_Wimplicit_int,
578038fd1498Szrj 			      "type defaults to %<int%> in type name");
578138fd1498Szrj 	}
578238fd1498Szrj     }
578338fd1498Szrj 
578438fd1498Szrj   /* Adjust the type if a bit-field is being declared,
578538fd1498Szrj      -funsigned-bitfields applied and the type is not explicitly
578638fd1498Szrj      "signed".  */
578738fd1498Szrj   if (bitfield && !flag_signed_bitfields && !declspecs->explicit_signed_p
578838fd1498Szrj       && TREE_CODE (type) == INTEGER_TYPE)
578938fd1498Szrj     type = unsigned_type_for (type);
579038fd1498Szrj 
579138fd1498Szrj   /* Figure out the type qualifiers for the declaration.  There are
579238fd1498Szrj      two ways a declaration can become qualified.  One is something
579338fd1498Szrj      like `const int i' where the `const' is explicit.  Another is
579438fd1498Szrj      something like `typedef const int CI; CI i' where the type of the
579538fd1498Szrj      declaration contains the `const'.  A third possibility is that
579638fd1498Szrj      there is a type qualifier on the element type of a typedefed
579738fd1498Szrj      array type, in which case we should extract that qualifier so
579838fd1498Szrj      that c_apply_type_quals_to_decl receives the full list of
579938fd1498Szrj      qualifiers to work with (C90 is not entirely clear about whether
580038fd1498Szrj      duplicate qualifiers should be diagnosed in this case, but it
580138fd1498Szrj      seems most appropriate to do so).  */
580238fd1498Szrj   element_type = strip_array_types (type);
580338fd1498Szrj   constp = declspecs->const_p + TYPE_READONLY (element_type);
580438fd1498Szrj   restrictp = declspecs->restrict_p + TYPE_RESTRICT (element_type);
580538fd1498Szrj   volatilep = declspecs->volatile_p + TYPE_VOLATILE (element_type);
580638fd1498Szrj   atomicp = declspecs->atomic_p + TYPE_ATOMIC (element_type);
580738fd1498Szrj   as1 = declspecs->address_space;
580838fd1498Szrj   as2 = TYPE_ADDR_SPACE (element_type);
580938fd1498Szrj   address_space = ADDR_SPACE_GENERIC_P (as1)? as2 : as1;
581038fd1498Szrj 
581138fd1498Szrj   if (constp > 1)
581238fd1498Szrj     pedwarn_c90 (loc, OPT_Wpedantic, "duplicate %<const%>");
581338fd1498Szrj   if (restrictp > 1)
581438fd1498Szrj     pedwarn_c90 (loc, OPT_Wpedantic, "duplicate %<restrict%>");
581538fd1498Szrj   if (volatilep > 1)
581638fd1498Szrj     pedwarn_c90 (loc, OPT_Wpedantic, "duplicate %<volatile%>");
581738fd1498Szrj   if (atomicp > 1)
581838fd1498Szrj     pedwarn_c90 (loc, OPT_Wpedantic, "duplicate %<_Atomic%>");
581938fd1498Szrj 
582038fd1498Szrj   if (!ADDR_SPACE_GENERIC_P (as1) && !ADDR_SPACE_GENERIC_P (as2) && as1 != as2)
582138fd1498Szrj     error_at (loc, "conflicting named address spaces (%s vs %s)",
582238fd1498Szrj 	      c_addr_space_name (as1), c_addr_space_name (as2));
582338fd1498Szrj 
582438fd1498Szrj   if ((TREE_CODE (type) == ARRAY_TYPE
582538fd1498Szrj        || first_non_attr_kind == cdk_array)
582638fd1498Szrj       && TYPE_QUALS (element_type))
582738fd1498Szrj     {
582838fd1498Szrj       orig_qual_type = type;
582938fd1498Szrj       type = TYPE_MAIN_VARIANT (type);
583038fd1498Szrj     }
583138fd1498Szrj   type_quals = ((constp ? TYPE_QUAL_CONST : 0)
583238fd1498Szrj 		| (restrictp ? TYPE_QUAL_RESTRICT : 0)
583338fd1498Szrj 		| (volatilep ? TYPE_QUAL_VOLATILE : 0)
583438fd1498Szrj 		| (atomicp ? TYPE_QUAL_ATOMIC : 0)
583538fd1498Szrj 		| ENCODE_QUAL_ADDR_SPACE (address_space));
583638fd1498Szrj   if (type_quals != TYPE_QUALS (element_type))
583738fd1498Szrj     orig_qual_type = NULL_TREE;
583838fd1498Szrj 
583938fd1498Szrj   /* Applying the _Atomic qualifier to an array type (through the use
584038fd1498Szrj      of typedefs or typeof) must be detected here.  If the qualifier
584138fd1498Szrj      is introduced later, any appearance of applying it to an array is
584238fd1498Szrj      actually applying it to an element of that array.  */
584338fd1498Szrj   if (declspecs->atomic_p && TREE_CODE (type) == ARRAY_TYPE)
584438fd1498Szrj     error_at (loc, "%<_Atomic%>-qualified array type");
584538fd1498Szrj 
584638fd1498Szrj   /* Warn about storage classes that are invalid for certain
584738fd1498Szrj      kinds of declarations (parameters, typenames, etc.).  */
584838fd1498Szrj 
584938fd1498Szrj   if (funcdef_flag
585038fd1498Szrj       && (threadp
585138fd1498Szrj 	  || storage_class == csc_auto
585238fd1498Szrj 	  || storage_class == csc_register
585338fd1498Szrj 	  || storage_class == csc_typedef))
585438fd1498Szrj     {
585538fd1498Szrj       if (storage_class == csc_auto)
585638fd1498Szrj 	pedwarn (loc,
585738fd1498Szrj 		 (current_scope == file_scope) ? 0 : OPT_Wpedantic,
585838fd1498Szrj 		 "function definition declared %<auto%>");
585938fd1498Szrj       if (storage_class == csc_register)
586038fd1498Szrj 	error_at (loc, "function definition declared %<register%>");
586138fd1498Szrj       if (storage_class == csc_typedef)
586238fd1498Szrj 	error_at (loc, "function definition declared %<typedef%>");
586338fd1498Szrj       if (threadp)
586438fd1498Szrj 	error_at (loc, "function definition declared %qs",
586538fd1498Szrj 		  declspecs->thread_gnu_p ? "__thread" : "_Thread_local");
586638fd1498Szrj       threadp = false;
586738fd1498Szrj       if (storage_class == csc_auto
586838fd1498Szrj 	  || storage_class == csc_register
586938fd1498Szrj 	  || storage_class == csc_typedef)
587038fd1498Szrj 	storage_class = csc_none;
587138fd1498Szrj     }
587238fd1498Szrj   else if (decl_context != NORMAL && (storage_class != csc_none || threadp))
587338fd1498Szrj     {
587438fd1498Szrj       if (decl_context == PARM && storage_class == csc_register)
587538fd1498Szrj 	;
587638fd1498Szrj       else
587738fd1498Szrj 	{
587838fd1498Szrj 	  switch (decl_context)
587938fd1498Szrj 	    {
588038fd1498Szrj 	    case FIELD:
588138fd1498Szrj 	      if (name)
588238fd1498Szrj 		error_at (loc, "storage class specified for structure "
588338fd1498Szrj 		    	  "field %qE", name);
588438fd1498Szrj 	      else
588538fd1498Szrj 		error_at (loc, "storage class specified for structure field");
588638fd1498Szrj 	      break;
588738fd1498Szrj 	    case PARM:
588838fd1498Szrj 	      if (name)
588938fd1498Szrj 		error_at (loc, "storage class specified for parameter %qE",
589038fd1498Szrj 		    	  name);
589138fd1498Szrj 	      else
589238fd1498Szrj 		error_at (loc, "storage class specified for unnamed parameter");
589338fd1498Szrj 	      break;
589438fd1498Szrj 	    default:
589538fd1498Szrj 	      error_at (loc, "storage class specified for typename");
589638fd1498Szrj 	      break;
589738fd1498Szrj 	    }
589838fd1498Szrj 	  storage_class = csc_none;
589938fd1498Szrj 	  threadp = false;
590038fd1498Szrj 	}
590138fd1498Szrj     }
590238fd1498Szrj   else if (storage_class == csc_extern
590338fd1498Szrj 	   && initialized
590438fd1498Szrj 	   && !funcdef_flag)
590538fd1498Szrj     {
590638fd1498Szrj       /* 'extern' with initialization is invalid if not at file scope.  */
590738fd1498Szrj        if (current_scope == file_scope)
590838fd1498Szrj          {
590938fd1498Szrj            /* It is fine to have 'extern const' when compiling at C
591038fd1498Szrj               and C++ intersection.  */
591138fd1498Szrj            if (!(warn_cxx_compat && constp))
591238fd1498Szrj              warning_at (loc, 0, "%qE initialized and declared %<extern%>",
591338fd1498Szrj 		 	 name);
591438fd1498Szrj          }
591538fd1498Szrj       else
591638fd1498Szrj 	error_at (loc, "%qE has both %<extern%> and initializer", name);
591738fd1498Szrj     }
591838fd1498Szrj   else if (current_scope == file_scope)
591938fd1498Szrj     {
592038fd1498Szrj       if (storage_class == csc_auto)
592138fd1498Szrj 	error_at (loc, "file-scope declaration of %qE specifies %<auto%>",
592238fd1498Szrj 	    	  name);
592338fd1498Szrj       if (pedantic && storage_class == csc_register)
592438fd1498Szrj 	pedwarn (input_location, OPT_Wpedantic,
592538fd1498Szrj 		 "file-scope declaration of %qE specifies %<register%>", name);
592638fd1498Szrj     }
592738fd1498Szrj   else
592838fd1498Szrj     {
592938fd1498Szrj       if (storage_class == csc_extern && funcdef_flag)
593038fd1498Szrj 	error_at (loc, "nested function %qE declared %<extern%>", name);
593138fd1498Szrj       else if (threadp && storage_class == csc_none)
593238fd1498Szrj 	{
593338fd1498Szrj 	  error_at (loc, "function-scope %qE implicitly auto and declared "
593438fd1498Szrj 		    "%qs", name,
593538fd1498Szrj 		    declspecs->thread_gnu_p ? "__thread" : "_Thread_local");
593638fd1498Szrj 	  threadp = false;
593738fd1498Szrj 	}
593838fd1498Szrj     }
593938fd1498Szrj 
594038fd1498Szrj   /* Now figure out the structure of the declarator proper.
594138fd1498Szrj      Descend through it, creating more complex types, until we reach
594238fd1498Szrj      the declared identifier (or NULL_TREE, in an absolute declarator).
594338fd1498Szrj      At each stage we maintain an unqualified version of the type
594438fd1498Szrj      together with any qualifiers that should be applied to it with
594538fd1498Szrj      c_build_qualified_type; this way, array types including
594638fd1498Szrj      multidimensional array types are first built up in unqualified
594738fd1498Szrj      form and then the qualified form is created with
594838fd1498Szrj      TYPE_MAIN_VARIANT pointing to the unqualified form.  */
594938fd1498Szrj 
595038fd1498Szrj   while (declarator && declarator->kind != cdk_id)
595138fd1498Szrj     {
595238fd1498Szrj       if (type == error_mark_node)
595338fd1498Szrj 	{
595438fd1498Szrj 	  declarator = declarator->declarator;
595538fd1498Szrj 	  continue;
595638fd1498Szrj 	}
595738fd1498Szrj 
595838fd1498Szrj       /* Each level of DECLARATOR is either a cdk_array (for ...[..]),
595938fd1498Szrj 	 a cdk_pointer (for *...),
596038fd1498Szrj 	 a cdk_function (for ...(...)),
596138fd1498Szrj 	 a cdk_attrs (for nested attributes),
596238fd1498Szrj 	 or a cdk_id (for the name being declared
596338fd1498Szrj 	 or the place in an absolute declarator
596438fd1498Szrj 	 where the name was omitted).
596538fd1498Szrj 	 For the last case, we have just exited the loop.
596638fd1498Szrj 
596738fd1498Szrj 	 At this point, TYPE is the type of elements of an array,
596838fd1498Szrj 	 or for a function to return, or for a pointer to point to.
596938fd1498Szrj 	 After this sequence of ifs, TYPE is the type of the
597038fd1498Szrj 	 array or function or pointer, and DECLARATOR has had its
597138fd1498Szrj 	 outermost layer removed.  */
597238fd1498Szrj 
597338fd1498Szrj       if (array_ptr_quals != TYPE_UNQUALIFIED
597438fd1498Szrj 	  || array_ptr_attrs != NULL_TREE
597538fd1498Szrj 	  || array_parm_static)
597638fd1498Szrj 	{
597738fd1498Szrj 	  /* Only the innermost declarator (making a parameter be of
597838fd1498Szrj 	     array type which is converted to pointer type)
597938fd1498Szrj 	     may have static or type qualifiers.  */
598038fd1498Szrj 	  error_at (loc, "static or type qualifiers in non-parameter array declarator");
598138fd1498Szrj 	  array_ptr_quals = TYPE_UNQUALIFIED;
598238fd1498Szrj 	  array_ptr_attrs = NULL_TREE;
598338fd1498Szrj 	  array_parm_static = false;
598438fd1498Szrj 	}
598538fd1498Szrj 
598638fd1498Szrj       switch (declarator->kind)
598738fd1498Szrj 	{
598838fd1498Szrj 	case cdk_attrs:
598938fd1498Szrj 	  {
599038fd1498Szrj 	    /* A declarator with embedded attributes.  */
599138fd1498Szrj 	    tree attrs = declarator->u.attrs;
599238fd1498Szrj 	    const struct c_declarator *inner_decl;
599338fd1498Szrj 	    int attr_flags = 0;
599438fd1498Szrj 	    declarator = declarator->declarator;
599538fd1498Szrj 	    inner_decl = declarator;
599638fd1498Szrj 	    while (inner_decl->kind == cdk_attrs)
599738fd1498Szrj 	      inner_decl = inner_decl->declarator;
599838fd1498Szrj 	    if (inner_decl->kind == cdk_id)
599938fd1498Szrj 	      attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
600038fd1498Szrj 	    else if (inner_decl->kind == cdk_function)
600138fd1498Szrj 	      attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
600238fd1498Szrj 	    else if (inner_decl->kind == cdk_array)
600338fd1498Szrj 	      attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
600438fd1498Szrj 	    returned_attrs = decl_attributes (&type,
600538fd1498Szrj 					      chainon (returned_attrs, attrs),
600638fd1498Szrj 					      attr_flags);
600738fd1498Szrj 	    break;
600838fd1498Szrj 	  }
600938fd1498Szrj 	case cdk_array:
601038fd1498Szrj 	  {
601138fd1498Szrj 	    tree itype = NULL_TREE;
601238fd1498Szrj 	    tree size = declarator->u.array.dimen;
601338fd1498Szrj 	    /* The index is a signed object `sizetype' bits wide.  */
601438fd1498Szrj 	    tree index_type = c_common_signed_type (sizetype);
601538fd1498Szrj 
601638fd1498Szrj 	    array_ptr_quals = declarator->u.array.quals;
601738fd1498Szrj 	    array_ptr_attrs = declarator->u.array.attrs;
601838fd1498Szrj 	    array_parm_static = declarator->u.array.static_p;
601938fd1498Szrj 	    array_parm_vla_unspec_p = declarator->u.array.vla_unspec_p;
602038fd1498Szrj 
602138fd1498Szrj 	    declarator = declarator->declarator;
602238fd1498Szrj 
602338fd1498Szrj 	    /* Check for some types that there cannot be arrays of.  */
602438fd1498Szrj 
602538fd1498Szrj 	    if (VOID_TYPE_P (type))
602638fd1498Szrj 	      {
602738fd1498Szrj 		if (name)
602838fd1498Szrj 		  error_at (loc, "declaration of %qE as array of voids", name);
602938fd1498Szrj 		else
603038fd1498Szrj 		  error_at (loc, "declaration of type name as array of voids");
603138fd1498Szrj 		type = error_mark_node;
603238fd1498Szrj 	      }
603338fd1498Szrj 
603438fd1498Szrj 	    if (TREE_CODE (type) == FUNCTION_TYPE)
603538fd1498Szrj 	      {
603638fd1498Szrj 		if (name)
603738fd1498Szrj 		  error_at (loc, "declaration of %qE as array of functions",
603838fd1498Szrj 		      	    name);
603938fd1498Szrj 		else
604038fd1498Szrj 		  error_at (loc, "declaration of type name as array of "
604138fd1498Szrj 		            "functions");
604238fd1498Szrj 		type = error_mark_node;
604338fd1498Szrj 	      }
604438fd1498Szrj 
604538fd1498Szrj 	    if (pedantic && !in_system_header_at (input_location)
604638fd1498Szrj 		&& flexible_array_type_p (type))
604738fd1498Szrj 	      pedwarn (loc, OPT_Wpedantic,
604838fd1498Szrj 		       "invalid use of structure with flexible array member");
604938fd1498Szrj 
605038fd1498Szrj 	    if (size == error_mark_node)
605138fd1498Szrj 	      type = error_mark_node;
605238fd1498Szrj 
605338fd1498Szrj 	    if (type == error_mark_node)
605438fd1498Szrj 	      continue;
605538fd1498Szrj 
605638fd1498Szrj 	    /* If size was specified, set ITYPE to a range-type for
605738fd1498Szrj 	       that size.  Otherwise, ITYPE remains null.  finish_decl
605838fd1498Szrj 	       may figure it out from an initial value.  */
605938fd1498Szrj 
606038fd1498Szrj 	    if (size)
606138fd1498Szrj 	      {
606238fd1498Szrj 		bool size_maybe_const = true;
606338fd1498Szrj 		bool size_int_const = (TREE_CODE (size) == INTEGER_CST
606438fd1498Szrj 				       && !TREE_OVERFLOW (size));
606538fd1498Szrj 		bool this_size_varies = false;
606638fd1498Szrj 
606738fd1498Szrj 		/* Strip NON_LVALUE_EXPRs since we aren't using as an
606838fd1498Szrj 		   lvalue.  */
606938fd1498Szrj 		STRIP_TYPE_NOPS (size);
607038fd1498Szrj 
607138fd1498Szrj 		if (!INTEGRAL_TYPE_P (TREE_TYPE (size)))
607238fd1498Szrj 		  {
607338fd1498Szrj 		    if (name)
607438fd1498Szrj 		      error_at (loc, "size of array %qE has non-integer type",
607538fd1498Szrj 				name);
607638fd1498Szrj 		    else
607738fd1498Szrj 		      error_at (loc,
607838fd1498Szrj 				"size of unnamed array has non-integer type");
607938fd1498Szrj 		    size = integer_one_node;
608038fd1498Szrj 		  }
608138fd1498Szrj 		/* This can happen with enum forward declaration.  */
608238fd1498Szrj 		else if (!COMPLETE_TYPE_P (TREE_TYPE (size)))
608338fd1498Szrj 		  {
608438fd1498Szrj 		    if (name)
608538fd1498Szrj 		      error_at (loc, "size of array %qE has incomplete type",
608638fd1498Szrj 				name);
608738fd1498Szrj 		    else
608838fd1498Szrj 		      error_at (loc, "size of unnamed array has incomplete "
608938fd1498Szrj 				"type");
609038fd1498Szrj 		    size = integer_one_node;
609138fd1498Szrj 		  }
609238fd1498Szrj 
609338fd1498Szrj 		size = c_fully_fold (size, false, &size_maybe_const);
609438fd1498Szrj 
609538fd1498Szrj 		if (pedantic && size_maybe_const && integer_zerop (size))
609638fd1498Szrj 		  {
609738fd1498Szrj 		    if (name)
609838fd1498Szrj 		      pedwarn (loc, OPT_Wpedantic,
609938fd1498Szrj 			       "ISO C forbids zero-size array %qE", name);
610038fd1498Szrj 		    else
610138fd1498Szrj 		      pedwarn (loc, OPT_Wpedantic,
610238fd1498Szrj 			       "ISO C forbids zero-size array");
610338fd1498Szrj 		  }
610438fd1498Szrj 
610538fd1498Szrj 		if (TREE_CODE (size) == INTEGER_CST && size_maybe_const)
610638fd1498Szrj 		  {
610738fd1498Szrj 		    constant_expression_warning (size);
610838fd1498Szrj 		    if (tree_int_cst_sgn (size) < 0)
610938fd1498Szrj 		      {
611038fd1498Szrj 			if (name)
611138fd1498Szrj 			  error_at (loc, "size of array %qE is negative", name);
611238fd1498Szrj 			else
611338fd1498Szrj 			  error_at (loc, "size of unnamed array is negative");
611438fd1498Szrj 			size = integer_one_node;
611538fd1498Szrj 		      }
611638fd1498Szrj 		    /* Handle a size folded to an integer constant but
611738fd1498Szrj 		       not an integer constant expression.  */
611838fd1498Szrj 		    if (!size_int_const)
611938fd1498Szrj 		      {
612038fd1498Szrj 			/* If this is a file scope declaration of an
612138fd1498Szrj 			   ordinary identifier, this is invalid code;
612238fd1498Szrj 			   diagnosing it here and not subsequently
612338fd1498Szrj 			   treating the type as variable-length avoids
612438fd1498Szrj 			   more confusing diagnostics later.  */
612538fd1498Szrj 			if ((decl_context == NORMAL || decl_context == FIELD)
612638fd1498Szrj 			    && current_scope == file_scope)
612738fd1498Szrj 			  pedwarn (input_location, 0,
612838fd1498Szrj 				   "variably modified %qE at file scope",
612938fd1498Szrj 				   name);
613038fd1498Szrj 			else
613138fd1498Szrj 			  this_size_varies = size_varies = true;
613238fd1498Szrj 			warn_variable_length_array (name, size);
613338fd1498Szrj 		      }
613438fd1498Szrj 		  }
613538fd1498Szrj 		else if ((decl_context == NORMAL || decl_context == FIELD)
613638fd1498Szrj 			 && current_scope == file_scope)
613738fd1498Szrj 		  {
613838fd1498Szrj 		    error_at (loc, "variably modified %qE at file scope", name);
613938fd1498Szrj 		    size = integer_one_node;
614038fd1498Szrj 		  }
614138fd1498Szrj 		else
614238fd1498Szrj 		  {
614338fd1498Szrj 		    /* Make sure the array size remains visibly
614438fd1498Szrj 		       nonconstant even if it is (eg) a const variable
614538fd1498Szrj 		       with known value.  */
614638fd1498Szrj 		    this_size_varies = size_varies = true;
614738fd1498Szrj 		    warn_variable_length_array (name, size);
614838fd1498Szrj 		    if (sanitize_flags_p (SANITIZE_VLA)
614938fd1498Szrj 			&& current_function_decl != NULL_TREE
615038fd1498Szrj 			&& decl_context == NORMAL)
615138fd1498Szrj 		      {
615238fd1498Szrj 			/* Evaluate the array size only once.  */
615338fd1498Szrj 			size = save_expr (size);
615438fd1498Szrj 			size = c_fully_fold (size, false, NULL);
615538fd1498Szrj 		        size = fold_build2 (COMPOUND_EXPR, TREE_TYPE (size),
615638fd1498Szrj 					    ubsan_instrument_vla (loc, size),
615738fd1498Szrj 					    size);
615838fd1498Szrj 		      }
615938fd1498Szrj 		  }
616038fd1498Szrj 
616138fd1498Szrj 		if (integer_zerop (size) && !this_size_varies)
616238fd1498Szrj 		  {
616338fd1498Szrj 		    /* A zero-length array cannot be represented with
616438fd1498Szrj 		       an unsigned index type, which is what we'll
616538fd1498Szrj 		       get with build_index_type.  Create an
616638fd1498Szrj 		       open-ended range instead.  */
616738fd1498Szrj 		    itype = build_range_type (sizetype, size, NULL_TREE);
616838fd1498Szrj 		  }
616938fd1498Szrj 		else
617038fd1498Szrj 		  {
617138fd1498Szrj 		    /* Arrange for the SAVE_EXPR on the inside of the
617238fd1498Szrj 		       MINUS_EXPR, which allows the -1 to get folded
617338fd1498Szrj 		       with the +1 that happens when building TYPE_SIZE.  */
617438fd1498Szrj 		    if (size_varies)
617538fd1498Szrj 		      size = save_expr (size);
617638fd1498Szrj 		    if (this_size_varies && TREE_CODE (size) == INTEGER_CST)
617738fd1498Szrj 		      size = build2 (COMPOUND_EXPR, TREE_TYPE (size),
617838fd1498Szrj 				     integer_zero_node, size);
617938fd1498Szrj 
618038fd1498Szrj 		    /* Compute the maximum valid index, that is, size
618138fd1498Szrj 		       - 1.  Do the calculation in index_type, so that
618238fd1498Szrj 		       if it is a variable the computations will be
618338fd1498Szrj 		       done in the proper mode.  */
618438fd1498Szrj 		    itype = fold_build2_loc (loc, MINUS_EXPR, index_type,
618538fd1498Szrj 					     convert (index_type, size),
618638fd1498Szrj 					     convert (index_type,
618738fd1498Szrj 						      size_one_node));
618838fd1498Szrj 
618938fd1498Szrj 		    /* The above overflows when size does not fit
619038fd1498Szrj 		       in index_type.
619138fd1498Szrj 		       ???  While a size of INT_MAX+1 technically shouldn't
619238fd1498Szrj 		       cause an overflow (because we subtract 1), handling
619338fd1498Szrj 		       this case seems like an unnecessary complication.  */
619438fd1498Szrj 		    if (TREE_CODE (size) == INTEGER_CST
619538fd1498Szrj 			&& !int_fits_type_p (size, index_type))
619638fd1498Szrj 		      {
619738fd1498Szrj 			if (name)
619838fd1498Szrj 			  error_at (loc, "size of array %qE is too large",
619938fd1498Szrj 			            name);
620038fd1498Szrj 			else
620138fd1498Szrj 			  error_at (loc, "size of unnamed array is too large");
620238fd1498Szrj 			type = error_mark_node;
620338fd1498Szrj 			continue;
620438fd1498Szrj 		      }
620538fd1498Szrj 
620638fd1498Szrj 		    itype = build_index_type (itype);
620738fd1498Szrj 		  }
620838fd1498Szrj 		if (this_size_varies)
620938fd1498Szrj 		  {
621038fd1498Szrj 		    if (*expr)
621138fd1498Szrj 		      *expr = build2 (COMPOUND_EXPR, TREE_TYPE (size),
621238fd1498Szrj 				      *expr, size);
621338fd1498Szrj 		    else
621438fd1498Szrj 		      *expr = size;
621538fd1498Szrj 		    *expr_const_operands &= size_maybe_const;
621638fd1498Szrj 		  }
621738fd1498Szrj 	      }
621838fd1498Szrj 	    else if (decl_context == FIELD)
621938fd1498Szrj 	      {
622038fd1498Szrj 		bool flexible_array_member = false;
622138fd1498Szrj 		if (array_parm_vla_unspec_p)
622238fd1498Szrj 		  /* Field names can in fact have function prototype
622338fd1498Szrj 		     scope so [*] is disallowed here through making
622438fd1498Szrj 		     the field variably modified, not through being
622538fd1498Szrj 		     something other than a declaration with function
622638fd1498Szrj 		     prototype scope.  */
622738fd1498Szrj 		  size_varies = true;
622838fd1498Szrj 		else
622938fd1498Szrj 		  {
623038fd1498Szrj 		    const struct c_declarator *t = declarator;
623138fd1498Szrj 		    while (t->kind == cdk_attrs)
623238fd1498Szrj 		      t = t->declarator;
623338fd1498Szrj 		    flexible_array_member = (t->kind == cdk_id);
623438fd1498Szrj 		  }
623538fd1498Szrj 		if (flexible_array_member
623638fd1498Szrj 		    && !in_system_header_at (input_location))
623738fd1498Szrj 		  pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not "
623838fd1498Szrj 			       "support flexible array members");
623938fd1498Szrj 
624038fd1498Szrj 		/* ISO C99 Flexible array members are effectively
624138fd1498Szrj 		   identical to GCC's zero-length array extension.  */
624238fd1498Szrj 		if (flexible_array_member || array_parm_vla_unspec_p)
624338fd1498Szrj 		  itype = build_range_type (sizetype, size_zero_node,
624438fd1498Szrj 					    NULL_TREE);
624538fd1498Szrj 	      }
624638fd1498Szrj 	    else if (decl_context == PARM)
624738fd1498Szrj 	      {
624838fd1498Szrj 		if (array_parm_vla_unspec_p)
624938fd1498Szrj 		  {
625038fd1498Szrj 		    itype = build_range_type (sizetype, size_zero_node, NULL_TREE);
625138fd1498Szrj 		    size_varies = true;
625238fd1498Szrj 		  }
625338fd1498Szrj 	      }
625438fd1498Szrj 	    else if (decl_context == TYPENAME)
625538fd1498Szrj 	      {
625638fd1498Szrj 		if (array_parm_vla_unspec_p)
625738fd1498Szrj 		  {
625838fd1498Szrj 		    /* C99 6.7.5.2p4 */
625938fd1498Szrj 		    warning (0, "%<[*]%> not in a declaration");
626038fd1498Szrj 		    /* We use this to avoid messing up with incomplete
626138fd1498Szrj 		       array types of the same type, that would
626238fd1498Szrj 		       otherwise be modified below.  */
626338fd1498Szrj 		    itype = build_range_type (sizetype, size_zero_node,
626438fd1498Szrj 					      NULL_TREE);
626538fd1498Szrj 		    size_varies = true;
626638fd1498Szrj 		  }
626738fd1498Szrj 	      }
626838fd1498Szrj 
626938fd1498Szrj 	    /* Complain about arrays of incomplete types.  */
627038fd1498Szrj 	    if (!COMPLETE_TYPE_P (type))
627138fd1498Szrj 	      {
627238fd1498Szrj 		error_at (loc, "array type has incomplete element type %qT",
627338fd1498Szrj 			  type);
627438fd1498Szrj 		/* See if we can be more helpful.  */
627538fd1498Szrj 		if (TREE_CODE (type) == ARRAY_TYPE)
627638fd1498Szrj 		  {
627738fd1498Szrj 		    if (name)
627838fd1498Szrj 		      inform (loc, "declaration of %qE as multidimensional "
627938fd1498Szrj 			      "array must have bounds for all dimensions "
628038fd1498Szrj 			      "except the first", name);
628138fd1498Szrj 		    else
628238fd1498Szrj 		      inform (loc, "declaration of multidimensional array "
628338fd1498Szrj 			      "must have bounds for all dimensions except "
628438fd1498Szrj 			      "the first");
628538fd1498Szrj 		  }
628638fd1498Szrj 		type = error_mark_node;
628738fd1498Szrj 	      }
628838fd1498Szrj 	    else
628938fd1498Szrj 	    /* When itype is NULL, a shared incomplete array type is
629038fd1498Szrj 	       returned for all array of a given type.  Elsewhere we
629138fd1498Szrj 	       make sure we don't complete that type before copying
629238fd1498Szrj 	       it, but here we want to make sure we don't ever
629338fd1498Szrj 	       modify the shared type, so we gcc_assert (itype)
629438fd1498Szrj 	       below.  */
629538fd1498Szrj 	      {
629638fd1498Szrj 		addr_space_t as = DECODE_QUAL_ADDR_SPACE (type_quals);
629738fd1498Szrj 		if (!ADDR_SPACE_GENERIC_P (as) && as != TYPE_ADDR_SPACE (type))
629838fd1498Szrj 		  type = build_qualified_type (type,
629938fd1498Szrj 					       ENCODE_QUAL_ADDR_SPACE (as));
630038fd1498Szrj 
630138fd1498Szrj 		type = build_array_type (type, itype);
630238fd1498Szrj 	      }
630338fd1498Szrj 
630438fd1498Szrj 	    if (type != error_mark_node)
630538fd1498Szrj 	      {
630638fd1498Szrj 		if (size_varies)
630738fd1498Szrj 		  {
630838fd1498Szrj 		    /* It is ok to modify type here even if itype is
630938fd1498Szrj 		       NULL: if size_varies, we're in a
631038fd1498Szrj 		       multi-dimensional array and the inner type has
631138fd1498Szrj 		       variable size, so the enclosing shared array type
631238fd1498Szrj 		       must too.  */
631338fd1498Szrj 		    if (size && TREE_CODE (size) == INTEGER_CST)
631438fd1498Szrj 		      type
631538fd1498Szrj 			= build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
631638fd1498Szrj 		    C_TYPE_VARIABLE_SIZE (type) = 1;
631738fd1498Szrj 		  }
631838fd1498Szrj 
631938fd1498Szrj 		/* The GCC extension for zero-length arrays differs from
632038fd1498Szrj 		   ISO flexible array members in that sizeof yields
632138fd1498Szrj 		   zero.  */
632238fd1498Szrj 		if (size && integer_zerop (size))
632338fd1498Szrj 		  {
632438fd1498Szrj 		    gcc_assert (itype);
632538fd1498Szrj 		    type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
632638fd1498Szrj 		    TYPE_SIZE (type) = bitsize_zero_node;
632738fd1498Szrj 		    TYPE_SIZE_UNIT (type) = size_zero_node;
632838fd1498Szrj 		    SET_TYPE_STRUCTURAL_EQUALITY (type);
632938fd1498Szrj 		  }
633038fd1498Szrj 		if (array_parm_vla_unspec_p)
633138fd1498Szrj 		  {
633238fd1498Szrj 		    gcc_assert (itype);
633338fd1498Szrj 		    /* The type is complete.  C99 6.7.5.2p4  */
633438fd1498Szrj 		    type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
633538fd1498Szrj 		    TYPE_SIZE (type) = bitsize_zero_node;
633638fd1498Szrj 		    TYPE_SIZE_UNIT (type) = size_zero_node;
633738fd1498Szrj 		    SET_TYPE_STRUCTURAL_EQUALITY (type);
633838fd1498Szrj 		  }
633938fd1498Szrj 
634038fd1498Szrj 		if (!valid_array_size_p (loc, type, name))
634138fd1498Szrj 		  type = error_mark_node;
634238fd1498Szrj 	      }
634338fd1498Szrj 
634438fd1498Szrj 	    if (decl_context != PARM
634538fd1498Szrj 		&& (array_ptr_quals != TYPE_UNQUALIFIED
634638fd1498Szrj 		    || array_ptr_attrs != NULL_TREE
634738fd1498Szrj 		    || array_parm_static))
634838fd1498Szrj 	      {
634938fd1498Szrj 		error_at (loc, "static or type qualifiers in non-parameter "
635038fd1498Szrj 			  "array declarator");
635138fd1498Szrj 		array_ptr_quals = TYPE_UNQUALIFIED;
635238fd1498Szrj 		array_ptr_attrs = NULL_TREE;
635338fd1498Szrj 		array_parm_static = false;
635438fd1498Szrj 	      }
635538fd1498Szrj 	    orig_qual_indirect++;
635638fd1498Szrj 	    break;
635738fd1498Szrj 	  }
635838fd1498Szrj 	case cdk_function:
635938fd1498Szrj 	  {
636038fd1498Szrj 	    /* Say it's a definition only for the declarator closest
636138fd1498Szrj 	       to the identifier, apart possibly from some
636238fd1498Szrj 	       attributes.  */
636338fd1498Szrj 	    bool really_funcdef = false;
636438fd1498Szrj 	    tree arg_types;
636538fd1498Szrj 	    orig_qual_type = NULL_TREE;
636638fd1498Szrj 	    if (funcdef_flag)
636738fd1498Szrj 	      {
636838fd1498Szrj 		const struct c_declarator *t = declarator->declarator;
636938fd1498Szrj 		while (t->kind == cdk_attrs)
637038fd1498Szrj 		  t = t->declarator;
637138fd1498Szrj 		really_funcdef = (t->kind == cdk_id);
637238fd1498Szrj 	      }
637338fd1498Szrj 
637438fd1498Szrj 	    /* Declaring a function type.  Make sure we have a valid
637538fd1498Szrj 	       type for the function to return.  */
637638fd1498Szrj 	    if (type == error_mark_node)
637738fd1498Szrj 	      continue;
637838fd1498Szrj 
637938fd1498Szrj 	    size_varies = false;
638038fd1498Szrj 
638138fd1498Szrj 	    /* Warn about some types functions can't return.  */
638238fd1498Szrj 	    if (TREE_CODE (type) == FUNCTION_TYPE)
638338fd1498Szrj 	      {
638438fd1498Szrj 		if (name)
638538fd1498Szrj 		  error_at (loc, "%qE declared as function returning a "
638638fd1498Szrj 		      		 "function", name);
638738fd1498Szrj 		else
638838fd1498Szrj 		  error_at (loc, "type name declared as function "
638938fd1498Szrj 			    "returning a function");
639038fd1498Szrj 		type = integer_type_node;
639138fd1498Szrj 	      }
639238fd1498Szrj 	    if (TREE_CODE (type) == ARRAY_TYPE)
639338fd1498Szrj 	      {
639438fd1498Szrj 		if (name)
639538fd1498Szrj 		  error_at (loc, "%qE declared as function returning an array",
639638fd1498Szrj 		      	    name);
639738fd1498Szrj 		else
639838fd1498Szrj 		  error_at (loc, "type name declared as function returning "
639938fd1498Szrj 		      	    "an array");
640038fd1498Szrj 		type = integer_type_node;
640138fd1498Szrj 	      }
640238fd1498Szrj 
640338fd1498Szrj 	    /* Construct the function type and go to the next
640438fd1498Szrj 	       inner layer of declarator.  */
640538fd1498Szrj 	    arg_info = declarator->u.arg_info;
640638fd1498Szrj 	    arg_types = grokparms (arg_info, really_funcdef);
640738fd1498Szrj 
640838fd1498Szrj 	    /* Type qualifiers before the return type of the function
640938fd1498Szrj 	       qualify the return type, not the function type.  */
641038fd1498Szrj 	    if (type_quals)
641138fd1498Szrj 	      {
641238fd1498Szrj 		const enum c_declspec_word ignored_quals_list[] =
641338fd1498Szrj 		  {
641438fd1498Szrj 		    cdw_const, cdw_volatile, cdw_restrict, cdw_address_space,
641538fd1498Szrj 		    cdw_atomic, cdw_number_of_elements
641638fd1498Szrj 		  };
641738fd1498Szrj 		location_t specs_loc
641838fd1498Szrj 		  = smallest_type_quals_location (declspecs->locations,
641938fd1498Szrj 						  ignored_quals_list);
642038fd1498Szrj 		if (specs_loc == UNKNOWN_LOCATION)
642138fd1498Szrj 		  specs_loc = declspecs->locations[cdw_typedef];
642238fd1498Szrj 		if (specs_loc == UNKNOWN_LOCATION)
642338fd1498Szrj 		  specs_loc = loc;
642438fd1498Szrj 
642538fd1498Szrj 		/* Type qualifiers on a function return type are
642638fd1498Szrj 		   normally permitted by the standard but have no
642738fd1498Szrj 		   effect, so give a warning at -Wreturn-type.
642838fd1498Szrj 		   Qualifiers on a void return type are banned on
642938fd1498Szrj 		   function definitions in ISO C; GCC used to used
643038fd1498Szrj 		   them for noreturn functions.  The resolution of C11
643138fd1498Szrj 		   DR#423 means qualifiers (other than _Atomic) are
643238fd1498Szrj 		   actually removed from the return type when
643338fd1498Szrj 		   determining the function type.  */
643438fd1498Szrj 		int quals_used = type_quals;
643538fd1498Szrj 		if (flag_isoc11)
643638fd1498Szrj 		  quals_used &= TYPE_QUAL_ATOMIC;
643738fd1498Szrj 		if (quals_used && VOID_TYPE_P (type) && really_funcdef)
643838fd1498Szrj 		  pedwarn (specs_loc, 0,
643938fd1498Szrj 			   "function definition has qualified void return type");
644038fd1498Szrj 		else
644138fd1498Szrj 		  warning_at (specs_loc, OPT_Wignored_qualifiers,
644238fd1498Szrj 			   "type qualifiers ignored on function return type");
644338fd1498Szrj 
644438fd1498Szrj 		/* Ensure an error for restrict on invalid types; the
644538fd1498Szrj 		   DR#423 resolution is not entirely clear about
644638fd1498Szrj 		   this.  */
644738fd1498Szrj 		if (flag_isoc11
644838fd1498Szrj 		    && (type_quals & TYPE_QUAL_RESTRICT)
644938fd1498Szrj 		    && (!POINTER_TYPE_P (type)
645038fd1498Szrj 			|| !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type))))
645138fd1498Szrj 		  error_at (loc, "invalid use of %<restrict%>");
645238fd1498Szrj 		if (quals_used)
645338fd1498Szrj 		  type = c_build_qualified_type (type, quals_used);
645438fd1498Szrj 	      }
645538fd1498Szrj 	    type_quals = TYPE_UNQUALIFIED;
645638fd1498Szrj 
645738fd1498Szrj 	    type = build_function_type (type, arg_types);
645838fd1498Szrj 	    declarator = declarator->declarator;
645938fd1498Szrj 
646038fd1498Szrj 	    /* Set the TYPE_CONTEXTs for each tagged type which is local to
646138fd1498Szrj 	       the formal parameter list of this FUNCTION_TYPE to point to
646238fd1498Szrj 	       the FUNCTION_TYPE node itself.  */
646338fd1498Szrj 	    {
646438fd1498Szrj 	      c_arg_tag *tag;
646538fd1498Szrj 	      unsigned ix;
646638fd1498Szrj 
646738fd1498Szrj 	      FOR_EACH_VEC_SAFE_ELT_REVERSE (arg_info->tags, ix, tag)
646838fd1498Szrj 		TYPE_CONTEXT (tag->type) = type;
646938fd1498Szrj 	    }
647038fd1498Szrj 	    break;
647138fd1498Szrj 	  }
647238fd1498Szrj 	case cdk_pointer:
647338fd1498Szrj 	  {
647438fd1498Szrj 	    /* Merge any constancy or volatility into the target type
647538fd1498Szrj 	       for the pointer.  */
647638fd1498Szrj 	    if ((type_quals & TYPE_QUAL_ATOMIC)
647738fd1498Szrj 		&& TREE_CODE (type) == FUNCTION_TYPE)
647838fd1498Szrj 	      {
647938fd1498Szrj 		error_at (loc,
648038fd1498Szrj 			  "%<_Atomic%>-qualified function type");
648138fd1498Szrj 		type_quals &= ~TYPE_QUAL_ATOMIC;
648238fd1498Szrj 	      }
648338fd1498Szrj 	    else if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
648438fd1498Szrj 		     && type_quals)
648538fd1498Szrj 	      pedwarn (loc, OPT_Wpedantic,
648638fd1498Szrj 		       "ISO C forbids qualified function types");
648738fd1498Szrj 	    if (type_quals)
648838fd1498Szrj 	      type = c_build_qualified_type (type, type_quals, orig_qual_type,
648938fd1498Szrj 					     orig_qual_indirect);
649038fd1498Szrj 	    orig_qual_type = NULL_TREE;
649138fd1498Szrj 	    size_varies = false;
649238fd1498Szrj 
649338fd1498Szrj 	    /* When the pointed-to type involves components of variable size,
649438fd1498Szrj 	       care must be taken to ensure that the size evaluation code is
649538fd1498Szrj 	       emitted early enough to dominate all the possible later uses
649638fd1498Szrj 	       and late enough for the variables on which it depends to have
649738fd1498Szrj 	       been assigned.
649838fd1498Szrj 
649938fd1498Szrj 	       This is expected to happen automatically when the pointed-to
650038fd1498Szrj 	       type has a name/declaration of it's own, but special attention
650138fd1498Szrj 	       is required if the type is anonymous.
650238fd1498Szrj 
650338fd1498Szrj 	       We attach an artificial TYPE_DECL to such pointed-to type
650438fd1498Szrj 	       and arrange for it to be included in a DECL_EXPR.  This
650538fd1498Szrj 	       forces the sizes evaluation at a safe point and ensures it
650638fd1498Szrj 	       is not deferred until e.g. within a deeper conditional context.
650738fd1498Szrj 
650838fd1498Szrj 	       PARM contexts have no enclosing statement list that
650938fd1498Szrj 	       can hold the DECL_EXPR, so we need to use a BIND_EXPR
651038fd1498Szrj 	       instead, and add it to the list of expressions that
651138fd1498Szrj 	       need to be evaluated.
651238fd1498Szrj 
651338fd1498Szrj 	       TYPENAME contexts do have an enclosing statement list,
651438fd1498Szrj 	       but it would be incorrect to use it, as the size should
651538fd1498Szrj 	       only be evaluated if the containing expression is
651638fd1498Szrj 	       evaluated.  We might also be in the middle of an
651738fd1498Szrj 	       expression with side effects on the pointed-to type size
651838fd1498Szrj 	       "arguments" prior to the pointer declaration point and
651938fd1498Szrj 	       the fake TYPE_DECL in the enclosing context would force
652038fd1498Szrj 	       the size evaluation prior to the side effects.  We therefore
652138fd1498Szrj 	       use BIND_EXPRs in TYPENAME contexts too.  */
652238fd1498Szrj 	    if (!TYPE_NAME (type)
652338fd1498Szrj 		&& variably_modified_type_p (type, NULL_TREE))
652438fd1498Szrj 	      {
652538fd1498Szrj 		tree bind = NULL_TREE;
652638fd1498Szrj 		if (decl_context == TYPENAME || decl_context == PARM)
652738fd1498Szrj 		  {
652838fd1498Szrj 		    bind = build3 (BIND_EXPR, void_type_node, NULL_TREE,
652938fd1498Szrj 				   NULL_TREE, NULL_TREE);
653038fd1498Szrj 		    TREE_SIDE_EFFECTS (bind) = 1;
653138fd1498Szrj 		    BIND_EXPR_BODY (bind) = push_stmt_list ();
653238fd1498Szrj 		    push_scope ();
653338fd1498Szrj 		  }
653438fd1498Szrj 		tree decl = build_decl (loc, TYPE_DECL, NULL_TREE, type);
653538fd1498Szrj 		DECL_ARTIFICIAL (decl) = 1;
653638fd1498Szrj 		pushdecl (decl);
653738fd1498Szrj 		finish_decl (decl, loc, NULL_TREE, NULL_TREE, NULL_TREE);
653838fd1498Szrj 		TYPE_NAME (type) = decl;
653938fd1498Szrj 		if (bind)
654038fd1498Szrj 		  {
654138fd1498Szrj 		    pop_scope ();
654238fd1498Szrj 		    BIND_EXPR_BODY (bind)
654338fd1498Szrj 		      = pop_stmt_list (BIND_EXPR_BODY (bind));
654438fd1498Szrj 		    if (*expr)
654538fd1498Szrj 		      *expr = build2 (COMPOUND_EXPR, void_type_node, *expr,
654638fd1498Szrj 				      bind);
654738fd1498Szrj 		    else
654838fd1498Szrj 		      *expr = bind;
654938fd1498Szrj 		  }
655038fd1498Szrj 	      }
655138fd1498Szrj 
655238fd1498Szrj 	    type = c_build_pointer_type (type);
655338fd1498Szrj 
655438fd1498Szrj 	    /* Process type qualifiers (such as const or volatile)
655538fd1498Szrj 	       that were given inside the `*'.  */
655638fd1498Szrj 	    type_quals = declarator->u.pointer_quals;
655738fd1498Szrj 
655838fd1498Szrj 	    declarator = declarator->declarator;
655938fd1498Szrj 	    break;
656038fd1498Szrj 	  }
656138fd1498Szrj 	default:
656238fd1498Szrj 	  gcc_unreachable ();
656338fd1498Szrj 	}
656438fd1498Szrj     }
656538fd1498Szrj   *decl_attrs = chainon (returned_attrs, *decl_attrs);
656638fd1498Szrj 
656738fd1498Szrj   /* Now TYPE has the actual type, apart from any qualifiers in
656838fd1498Szrj      TYPE_QUALS.  */
656938fd1498Szrj 
657038fd1498Szrj   /* Warn about address space used for things other than static memory or
657138fd1498Szrj      pointers.  */
657238fd1498Szrj   address_space = DECODE_QUAL_ADDR_SPACE (type_quals);
657338fd1498Szrj   if (!ADDR_SPACE_GENERIC_P (address_space))
657438fd1498Szrj     {
657538fd1498Szrj       if (decl_context == NORMAL)
657638fd1498Szrj 	{
657738fd1498Szrj 	  switch (storage_class)
657838fd1498Szrj 	    {
657938fd1498Szrj 	    case csc_auto:
658038fd1498Szrj 	      error ("%qs combined with %<auto%> qualifier for %qE",
658138fd1498Szrj 		     c_addr_space_name (address_space), name);
658238fd1498Szrj 	      break;
658338fd1498Szrj 	    case csc_register:
658438fd1498Szrj 	      error ("%qs combined with %<register%> qualifier for %qE",
658538fd1498Szrj 		     c_addr_space_name (address_space), name);
658638fd1498Szrj 	      break;
658738fd1498Szrj 	    case csc_none:
658838fd1498Szrj 	      if (current_function_scope)
658938fd1498Szrj 		{
659038fd1498Szrj 		  error ("%qs specified for auto variable %qE",
659138fd1498Szrj 			 c_addr_space_name (address_space), name);
659238fd1498Szrj 		  break;
659338fd1498Szrj 		}
659438fd1498Szrj 	      break;
659538fd1498Szrj 	    case csc_static:
659638fd1498Szrj 	    case csc_extern:
659738fd1498Szrj 	    case csc_typedef:
659838fd1498Szrj 	      break;
659938fd1498Szrj 	    default:
660038fd1498Szrj 	      gcc_unreachable ();
660138fd1498Szrj 	    }
660238fd1498Szrj 	}
660338fd1498Szrj       else if (decl_context == PARM && TREE_CODE (type) != ARRAY_TYPE)
660438fd1498Szrj 	{
660538fd1498Szrj 	  if (name)
660638fd1498Szrj 	    error ("%qs specified for parameter %qE",
660738fd1498Szrj 		   c_addr_space_name (address_space), name);
660838fd1498Szrj 	  else
660938fd1498Szrj 	    error ("%qs specified for unnamed parameter",
661038fd1498Szrj 		   c_addr_space_name (address_space));
661138fd1498Szrj 	}
661238fd1498Szrj       else if (decl_context == FIELD)
661338fd1498Szrj 	{
661438fd1498Szrj 	  if (name)
661538fd1498Szrj 	    error ("%qs specified for structure field %qE",
661638fd1498Szrj 		   c_addr_space_name (address_space), name);
661738fd1498Szrj 	  else
661838fd1498Szrj 	    error ("%qs specified for structure field",
661938fd1498Szrj 		   c_addr_space_name (address_space));
662038fd1498Szrj 	}
662138fd1498Szrj     }
662238fd1498Szrj 
662338fd1498Szrj   /* Check the type and width of a bit-field.  */
662438fd1498Szrj   if (bitfield)
662538fd1498Szrj     {
662638fd1498Szrj       check_bitfield_type_and_width (loc, &type, width, name);
662738fd1498Szrj       /* C11 makes it implementation-defined (6.7.2.1#5) whether
662838fd1498Szrj 	 atomic types are permitted for bit-fields; we have no code to
662938fd1498Szrj 	 make bit-field accesses atomic, so disallow them.  */
663038fd1498Szrj       if (type_quals & TYPE_QUAL_ATOMIC)
663138fd1498Szrj 	{
663238fd1498Szrj 	  if (name)
663338fd1498Szrj 	    error_at (loc, "bit-field %qE has atomic type", name);
663438fd1498Szrj 	  else
663538fd1498Szrj 	    error_at (loc, "bit-field has atomic type");
663638fd1498Szrj 	  type_quals &= ~TYPE_QUAL_ATOMIC;
663738fd1498Szrj 	}
663838fd1498Szrj     }
663938fd1498Szrj 
664038fd1498Szrj   /* Reject invalid uses of _Alignas.  */
664138fd1498Szrj   if (declspecs->alignas_p)
664238fd1498Szrj     {
664338fd1498Szrj       if (storage_class == csc_typedef)
664438fd1498Szrj 	error_at (loc, "alignment specified for typedef %qE", name);
664538fd1498Szrj       else if (storage_class == csc_register)
664638fd1498Szrj 	error_at (loc, "alignment specified for %<register%> object %qE",
664738fd1498Szrj 		  name);
664838fd1498Szrj       else if (decl_context == PARM)
664938fd1498Szrj 	{
665038fd1498Szrj 	  if (name)
665138fd1498Szrj 	    error_at (loc, "alignment specified for parameter %qE", name);
665238fd1498Szrj 	  else
665338fd1498Szrj 	    error_at (loc, "alignment specified for unnamed parameter");
665438fd1498Szrj 	}
665538fd1498Szrj       else if (bitfield)
665638fd1498Szrj 	{
665738fd1498Szrj 	  if (name)
665838fd1498Szrj 	    error_at (loc, "alignment specified for bit-field %qE", name);
665938fd1498Szrj 	  else
666038fd1498Szrj 	    error_at (loc, "alignment specified for unnamed bit-field");
666138fd1498Szrj 	}
666238fd1498Szrj       else if (TREE_CODE (type) == FUNCTION_TYPE)
666338fd1498Szrj 	error_at (loc, "alignment specified for function %qE", name);
666438fd1498Szrj       else if (declspecs->align_log != -1 && TYPE_P (type))
666538fd1498Szrj 	{
666638fd1498Szrj 	  alignas_align = 1U << declspecs->align_log;
666738fd1498Szrj 	  if (alignas_align < min_align_of_type (type))
666838fd1498Szrj 	    {
666938fd1498Szrj 	      if (name)
667038fd1498Szrj 		error_at (loc, "%<_Alignas%> specifiers cannot reduce "
667138fd1498Szrj 			  "alignment of %qE", name);
667238fd1498Szrj 	      else
667338fd1498Szrj 		error_at (loc, "%<_Alignas%> specifiers cannot reduce "
667438fd1498Szrj 			  "alignment of unnamed field");
667538fd1498Szrj 	      alignas_align = 0;
667638fd1498Szrj 	    }
667738fd1498Szrj 	}
667838fd1498Szrj     }
667938fd1498Szrj 
668038fd1498Szrj   /* If this is declaring a typedef name, return a TYPE_DECL.  */
668138fd1498Szrj 
668238fd1498Szrj   if (storage_class == csc_typedef)
668338fd1498Szrj     {
668438fd1498Szrj       tree decl;
668538fd1498Szrj       if ((type_quals & TYPE_QUAL_ATOMIC)
668638fd1498Szrj 	  && TREE_CODE (type) == FUNCTION_TYPE)
668738fd1498Szrj 	{
668838fd1498Szrj 	  error_at (loc,
668938fd1498Szrj 		    "%<_Atomic%>-qualified function type");
669038fd1498Szrj 	  type_quals &= ~TYPE_QUAL_ATOMIC;
669138fd1498Szrj 	}
669238fd1498Szrj       else if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
669338fd1498Szrj 	       && type_quals)
669438fd1498Szrj 	pedwarn (loc, OPT_Wpedantic,
669538fd1498Szrj 		 "ISO C forbids qualified function types");
669638fd1498Szrj       if (type_quals)
669738fd1498Szrj 	type = c_build_qualified_type (type, type_quals, orig_qual_type,
669838fd1498Szrj 				       orig_qual_indirect);
669938fd1498Szrj       decl = build_decl (declarator->id_loc,
670038fd1498Szrj 			 TYPE_DECL, declarator->u.id, type);
670138fd1498Szrj       if (declspecs->explicit_signed_p)
670238fd1498Szrj 	C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
670338fd1498Szrj       if (declspecs->inline_p)
670438fd1498Szrj 	pedwarn (loc, 0,"typedef %q+D declared %<inline%>", decl);
670538fd1498Szrj       if (declspecs->noreturn_p)
670638fd1498Szrj 	pedwarn (loc, 0,"typedef %q+D declared %<_Noreturn%>", decl);
670738fd1498Szrj 
670838fd1498Szrj       if (warn_cxx_compat && declarator->u.id != NULL_TREE)
670938fd1498Szrj 	{
671038fd1498Szrj 	  struct c_binding *b = I_TAG_BINDING (declarator->u.id);
671138fd1498Szrj 
671238fd1498Szrj 	  if (b != NULL
671338fd1498Szrj 	      && b->decl != NULL_TREE
671438fd1498Szrj 	      && (B_IN_CURRENT_SCOPE (b)
671538fd1498Szrj 		  || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
671638fd1498Szrj 	      && TYPE_MAIN_VARIANT (b->decl) != TYPE_MAIN_VARIANT (type))
671738fd1498Szrj 	    {
671838fd1498Szrj 	      if (warning_at (declarator->id_loc, OPT_Wc___compat,
671938fd1498Szrj 			      ("using %qD as both a typedef and a tag is "
672038fd1498Szrj 			       "invalid in C++"), decl)
672138fd1498Szrj 		  && b->locus != UNKNOWN_LOCATION)
672238fd1498Szrj 		inform (b->locus, "originally defined here");
672338fd1498Szrj 	    }
672438fd1498Szrj 	}
672538fd1498Szrj 
672638fd1498Szrj       return decl;
672738fd1498Szrj     }
672838fd1498Szrj 
672938fd1498Szrj   /* If this is a type name (such as, in a cast or sizeof),
673038fd1498Szrj      compute the type and return it now.  */
673138fd1498Szrj 
673238fd1498Szrj   if (decl_context == TYPENAME)
673338fd1498Szrj     {
673438fd1498Szrj       /* Note that the grammar rejects storage classes in typenames
673538fd1498Szrj 	 and fields.  */
673638fd1498Szrj       gcc_assert (storage_class == csc_none && !threadp
673738fd1498Szrj 		  && !declspecs->inline_p && !declspecs->noreturn_p);
673838fd1498Szrj       if ((type_quals & TYPE_QUAL_ATOMIC)
673938fd1498Szrj 	  && TREE_CODE (type) == FUNCTION_TYPE)
674038fd1498Szrj 	{
674138fd1498Szrj 	  error_at (loc,
674238fd1498Szrj 		    "%<_Atomic%>-qualified function type");
674338fd1498Szrj 	  type_quals &= ~TYPE_QUAL_ATOMIC;
674438fd1498Szrj 	}
674538fd1498Szrj       else if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
674638fd1498Szrj 	       && type_quals)
674738fd1498Szrj 	pedwarn (loc, OPT_Wpedantic,
674838fd1498Szrj 		 "ISO C forbids const or volatile function types");
674938fd1498Szrj       if (type_quals)
675038fd1498Szrj 	type = c_build_qualified_type (type, type_quals, orig_qual_type,
675138fd1498Szrj 				       orig_qual_indirect);
675238fd1498Szrj       return type;
675338fd1498Szrj     }
675438fd1498Szrj 
675538fd1498Szrj   if (pedantic && decl_context == FIELD
675638fd1498Szrj       && variably_modified_type_p (type, NULL_TREE))
675738fd1498Szrj     {
675838fd1498Szrj       /* C99 6.7.2.1p8 */
675938fd1498Szrj       pedwarn (loc, OPT_Wpedantic, "a member of a structure or union cannot "
676038fd1498Szrj 	       "have a variably modified type");
676138fd1498Szrj     }
676238fd1498Szrj 
676338fd1498Szrj   /* Aside from typedefs and type names (handle above),
676438fd1498Szrj      `void' at top level (not within pointer)
676538fd1498Szrj      is allowed only in public variables.
676638fd1498Szrj      We don't complain about parms either, but that is because
676738fd1498Szrj      a better error message can be made later.  */
676838fd1498Szrj 
676938fd1498Szrj   if (VOID_TYPE_P (type) && decl_context != PARM
677038fd1498Szrj       && !((decl_context != FIELD && TREE_CODE (type) != FUNCTION_TYPE)
677138fd1498Szrj 	    && (storage_class == csc_extern
677238fd1498Szrj 		|| (current_scope == file_scope
677338fd1498Szrj 		    && !(storage_class == csc_static
677438fd1498Szrj 			 || storage_class == csc_register)))))
677538fd1498Szrj     {
677638fd1498Szrj       error_at (loc, "variable or field %qE declared void", name);
677738fd1498Szrj       type = integer_type_node;
677838fd1498Szrj     }
677938fd1498Szrj 
678038fd1498Szrj   /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
678138fd1498Szrj      or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE.  */
678238fd1498Szrj 
678338fd1498Szrj   {
678438fd1498Szrj     tree decl;
678538fd1498Szrj 
678638fd1498Szrj     if (decl_context == PARM)
678738fd1498Szrj       {
678838fd1498Szrj 	tree promoted_type;
678938fd1498Szrj 	bool array_parameter_p = false;
679038fd1498Szrj 
679138fd1498Szrj 	/* A parameter declared as an array of T is really a pointer to T.
679238fd1498Szrj 	   One declared as a function is really a pointer to a function.  */
679338fd1498Szrj 
679438fd1498Szrj 	if (TREE_CODE (type) == ARRAY_TYPE)
679538fd1498Szrj 	  {
679638fd1498Szrj 	    /* Transfer const-ness of array into that of type pointed to.  */
679738fd1498Szrj 	    type = TREE_TYPE (type);
679838fd1498Szrj 	    if (orig_qual_type != NULL_TREE)
679938fd1498Szrj 	      {
680038fd1498Szrj 		if (orig_qual_indirect == 0)
680138fd1498Szrj 		  orig_qual_type = TREE_TYPE (orig_qual_type);
680238fd1498Szrj 		else
680338fd1498Szrj 		  orig_qual_indirect--;
680438fd1498Szrj 	      }
680538fd1498Szrj 	    if (type_quals)
680638fd1498Szrj 	      type = c_build_qualified_type (type, type_quals, orig_qual_type,
680738fd1498Szrj 					     orig_qual_indirect);
680838fd1498Szrj 	    type = c_build_pointer_type (type);
680938fd1498Szrj 	    type_quals = array_ptr_quals;
681038fd1498Szrj 	    if (type_quals)
681138fd1498Szrj 	      type = c_build_qualified_type (type, type_quals);
681238fd1498Szrj 
681338fd1498Szrj 	    /* We don't yet implement attributes in this context.  */
681438fd1498Szrj 	    if (array_ptr_attrs != NULL_TREE)
681538fd1498Szrj 	      warning_at (loc, OPT_Wattributes,
681638fd1498Szrj 			  "attributes in parameter array declarator ignored");
681738fd1498Szrj 
681838fd1498Szrj 	    size_varies = false;
681938fd1498Szrj 	    array_parameter_p = true;
682038fd1498Szrj 	  }
682138fd1498Szrj 	else if (TREE_CODE (type) == FUNCTION_TYPE)
682238fd1498Szrj 	  {
682338fd1498Szrj 	    if (type_quals & TYPE_QUAL_ATOMIC)
682438fd1498Szrj 	      {
682538fd1498Szrj 		error_at (loc,
682638fd1498Szrj 			  "%<_Atomic%>-qualified function type");
682738fd1498Szrj 		type_quals &= ~TYPE_QUAL_ATOMIC;
682838fd1498Szrj 	      }
682938fd1498Szrj 	    else if (type_quals)
683038fd1498Szrj 	      pedwarn (loc, OPT_Wpedantic,
683138fd1498Szrj 		       "ISO C forbids qualified function types");
683238fd1498Szrj 	    if (type_quals)
683338fd1498Szrj 	      type = c_build_qualified_type (type, type_quals);
683438fd1498Szrj 	    type = c_build_pointer_type (type);
683538fd1498Szrj 	    type_quals = TYPE_UNQUALIFIED;
683638fd1498Szrj 	  }
683738fd1498Szrj 	else if (type_quals)
683838fd1498Szrj 	  type = c_build_qualified_type (type, type_quals);
683938fd1498Szrj 
684038fd1498Szrj 	decl = build_decl (declarator->id_loc,
684138fd1498Szrj 			   PARM_DECL, declarator->u.id, type);
684238fd1498Szrj 	if (size_varies)
684338fd1498Szrj 	  C_DECL_VARIABLE_SIZE (decl) = 1;
684438fd1498Szrj 	C_ARRAY_PARAMETER (decl) = array_parameter_p;
684538fd1498Szrj 
684638fd1498Szrj 	/* Compute the type actually passed in the parmlist,
684738fd1498Szrj 	   for the case where there is no prototype.
684838fd1498Szrj 	   (For example, shorts and chars are passed as ints.)
684938fd1498Szrj 	   When there is a prototype, this is overridden later.  */
685038fd1498Szrj 
685138fd1498Szrj 	if (type == error_mark_node)
685238fd1498Szrj 	  promoted_type = type;
685338fd1498Szrj 	else
685438fd1498Szrj 	  promoted_type = c_type_promotes_to (type);
685538fd1498Szrj 
685638fd1498Szrj 	DECL_ARG_TYPE (decl) = promoted_type;
685738fd1498Szrj 	if (declspecs->inline_p)
685838fd1498Szrj 	  pedwarn (loc, 0, "parameter %q+D declared %<inline%>", decl);
685938fd1498Szrj 	if (declspecs->noreturn_p)
686038fd1498Szrj 	  pedwarn (loc, 0, "parameter %q+D declared %<_Noreturn%>", decl);
686138fd1498Szrj       }
686238fd1498Szrj     else if (decl_context == FIELD)
686338fd1498Szrj       {
686438fd1498Szrj 	/* Note that the grammar rejects storage classes in typenames
686538fd1498Szrj 	   and fields.  */
686638fd1498Szrj 	gcc_assert (storage_class == csc_none && !threadp
686738fd1498Szrj 		    && !declspecs->inline_p && !declspecs->noreturn_p);
686838fd1498Szrj 
686938fd1498Szrj 	/* Structure field.  It may not be a function.  */
687038fd1498Szrj 
687138fd1498Szrj 	if (TREE_CODE (type) == FUNCTION_TYPE)
687238fd1498Szrj 	  {
687338fd1498Szrj 	    error_at (loc, "field %qE declared as a function", name);
687438fd1498Szrj 	    type = build_pointer_type (type);
687538fd1498Szrj 	  }
687638fd1498Szrj 	else if (TREE_CODE (type) != ERROR_MARK
687738fd1498Szrj 		 && !COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (type))
687838fd1498Szrj 	  {
687938fd1498Szrj 	    if (name)
688038fd1498Szrj 	      error_at (loc, "field %qE has incomplete type", name);
688138fd1498Szrj 	    else
688238fd1498Szrj 	      error_at (loc, "unnamed field has incomplete type");
688338fd1498Szrj 	    type = error_mark_node;
688438fd1498Szrj 	  }
688538fd1498Szrj 	else if (TREE_CODE (type) == ARRAY_TYPE
688638fd1498Szrj 		 && TYPE_DOMAIN (type) == NULL_TREE)
688738fd1498Szrj 	  {
688838fd1498Szrj 	    /* We have a flexible array member through a typedef.
688938fd1498Szrj 	       Set suitable range.  Whether this is a correct position
689038fd1498Szrj 	       for a flexible array member will be determined elsewhere.  */
689138fd1498Szrj 	    if (!in_system_header_at (input_location))
689238fd1498Szrj 	      pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not "
689338fd1498Szrj 			   "support flexible array members");
689438fd1498Szrj 	    type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
689538fd1498Szrj 	    TYPE_DOMAIN (type) = build_range_type (sizetype, size_zero_node,
689638fd1498Szrj 						   NULL_TREE);
689738fd1498Szrj 	    if (orig_qual_indirect == 0)
689838fd1498Szrj 	      orig_qual_type = NULL_TREE;
689938fd1498Szrj 	  }
690038fd1498Szrj 	type = c_build_qualified_type (type, type_quals, orig_qual_type,
690138fd1498Szrj 				       orig_qual_indirect);
690238fd1498Szrj 	decl = build_decl (declarator->id_loc,
690338fd1498Szrj 			   FIELD_DECL, declarator->u.id, type);
690438fd1498Szrj 	DECL_NONADDRESSABLE_P (decl) = bitfield;
690538fd1498Szrj 	if (bitfield && !declarator->u.id)
690638fd1498Szrj 	  {
690738fd1498Szrj 	    TREE_NO_WARNING (decl) = 1;
690838fd1498Szrj 	    DECL_PADDING_P (decl) = 1;
690938fd1498Szrj 	  }
691038fd1498Szrj 
691138fd1498Szrj 	if (size_varies)
691238fd1498Szrj 	  C_DECL_VARIABLE_SIZE (decl) = 1;
691338fd1498Szrj       }
691438fd1498Szrj     else if (TREE_CODE (type) == FUNCTION_TYPE)
691538fd1498Szrj       {
691638fd1498Szrj 	if (storage_class == csc_register || threadp)
691738fd1498Szrj 	  {
691838fd1498Szrj 	    error_at (loc, "invalid storage class for function %qE", name);
691938fd1498Szrj 	  }
692038fd1498Szrj 	else if (current_scope != file_scope)
692138fd1498Szrj 	  {
692238fd1498Szrj 	    /* Function declaration not at file scope.  Storage
692338fd1498Szrj 	       classes other than `extern' are not allowed, C99
692438fd1498Szrj 	       6.7.1p5, and `extern' makes no difference.  However,
692538fd1498Szrj 	       GCC allows 'auto', perhaps with 'inline', to support
692638fd1498Szrj 	       nested functions.  */
692738fd1498Szrj 	    if (storage_class == csc_auto)
692838fd1498Szrj 		pedwarn (loc, OPT_Wpedantic,
692938fd1498Szrj 			 "invalid storage class for function %qE", name);
693038fd1498Szrj 	    else if (storage_class == csc_static)
693138fd1498Szrj 	      {
693238fd1498Szrj 		error_at (loc, "invalid storage class for function %qE", name);
693338fd1498Szrj 		if (funcdef_flag)
693438fd1498Szrj 		  storage_class = declspecs->storage_class = csc_none;
693538fd1498Szrj 		else
693638fd1498Szrj 		  return NULL_TREE;
693738fd1498Szrj 	      }
693838fd1498Szrj 	  }
693938fd1498Szrj 
694038fd1498Szrj 	decl = build_decl (declarator->id_loc,
694138fd1498Szrj 			   FUNCTION_DECL, declarator->u.id, type);
694238fd1498Szrj 	decl = build_decl_attribute_variant (decl, decl_attr);
694338fd1498Szrj 
694438fd1498Szrj 	if (type_quals & TYPE_QUAL_ATOMIC)
694538fd1498Szrj 	  {
694638fd1498Szrj 	    error_at (loc,
694738fd1498Szrj 		      "%<_Atomic%>-qualified function type");
694838fd1498Szrj 	    type_quals &= ~TYPE_QUAL_ATOMIC;
694938fd1498Szrj 	  }
695038fd1498Szrj 	else if (pedantic && type_quals && !DECL_IN_SYSTEM_HEADER (decl))
695138fd1498Szrj 	  pedwarn (loc, OPT_Wpedantic,
695238fd1498Szrj 		   "ISO C forbids qualified function types");
695338fd1498Szrj 
695438fd1498Szrj 	/* Every function declaration is an external reference
695538fd1498Szrj 	   (DECL_EXTERNAL) except for those which are not at file
695638fd1498Szrj 	   scope and are explicitly declared "auto".  This is
695738fd1498Szrj 	   forbidden by standard C (C99 6.7.1p5) and is interpreted by
695838fd1498Szrj 	   GCC to signify a forward declaration of a nested function.  */
695938fd1498Szrj 	if (storage_class == csc_auto && current_scope != file_scope)
696038fd1498Szrj 	  DECL_EXTERNAL (decl) = 0;
696138fd1498Szrj 	/* In C99, a function which is declared 'inline' with 'extern'
696238fd1498Szrj 	   is not an external reference (which is confusing).  It
696338fd1498Szrj 	   means that the later definition of the function must be output
696438fd1498Szrj 	   in this file, C99 6.7.4p6.  In GNU C89, a function declared
696538fd1498Szrj 	   'extern inline' is an external reference.  */
696638fd1498Szrj 	else if (declspecs->inline_p && storage_class != csc_static)
696738fd1498Szrj 	  DECL_EXTERNAL (decl) = ((storage_class == csc_extern)
696838fd1498Szrj 				  == flag_gnu89_inline);
696938fd1498Szrj 	else
697038fd1498Szrj 	  DECL_EXTERNAL (decl) = !initialized;
697138fd1498Szrj 
697238fd1498Szrj 	/* Record absence of global scope for `static' or `auto'.  */
697338fd1498Szrj 	TREE_PUBLIC (decl)
697438fd1498Szrj 	  = !(storage_class == csc_static || storage_class == csc_auto);
697538fd1498Szrj 
697638fd1498Szrj 	/* For a function definition, record the argument information
697738fd1498Szrj 	   block where store_parm_decls will look for it.  */
697838fd1498Szrj 	if (funcdef_flag)
697938fd1498Szrj 	  current_function_arg_info = arg_info;
698038fd1498Szrj 
698138fd1498Szrj 	if (declspecs->default_int_p)
698238fd1498Szrj 	  C_FUNCTION_IMPLICIT_INT (decl) = 1;
698338fd1498Szrj 
698438fd1498Szrj 	/* Record presence of `inline' and `_Noreturn', if it is
698538fd1498Szrj 	   reasonable.  */
698638fd1498Szrj 	if (flag_hosted && MAIN_NAME_P (declarator->u.id))
698738fd1498Szrj 	  {
698838fd1498Szrj 	    if (declspecs->inline_p)
698938fd1498Szrj 	      pedwarn (loc, 0, "cannot inline function %<main%>");
699038fd1498Szrj 	    if (declspecs->noreturn_p)
699138fd1498Szrj 	      pedwarn (loc, 0, "%<main%> declared %<_Noreturn%>");
699238fd1498Szrj 	  }
699338fd1498Szrj 	else
699438fd1498Szrj 	  {
699538fd1498Szrj 	    if (declspecs->inline_p)
699638fd1498Szrj 	      /* Record that the function is declared `inline'.  */
699738fd1498Szrj 	      DECL_DECLARED_INLINE_P (decl) = 1;
699838fd1498Szrj 	    if (declspecs->noreturn_p)
699938fd1498Szrj 	      {
700038fd1498Szrj 		if (flag_isoc99)
700138fd1498Szrj 		  pedwarn_c99 (loc, OPT_Wpedantic,
700238fd1498Szrj 			       "ISO C99 does not support %<_Noreturn%>");
700338fd1498Szrj 		else
700438fd1498Szrj 		  pedwarn_c99 (loc, OPT_Wpedantic,
700538fd1498Szrj 			       "ISO C90 does not support %<_Noreturn%>");
700638fd1498Szrj 		TREE_THIS_VOLATILE (decl) = 1;
700738fd1498Szrj 	      }
700838fd1498Szrj 	  }
700938fd1498Szrj       }
701038fd1498Szrj     else
701138fd1498Szrj       {
701238fd1498Szrj 	/* It's a variable.  */
701338fd1498Szrj 	/* An uninitialized decl with `extern' is a reference.  */
701438fd1498Szrj 	int extern_ref = !initialized && storage_class == csc_extern;
701538fd1498Szrj 
701638fd1498Szrj 	type = c_build_qualified_type (type, type_quals, orig_qual_type,
701738fd1498Szrj 				       orig_qual_indirect);
701838fd1498Szrj 
701938fd1498Szrj 	/* C99 6.2.2p7: It is invalid (compile-time undefined
702038fd1498Szrj 	   behavior) to create an 'extern' declaration for a
702138fd1498Szrj 	   variable if there is a global declaration that is
702238fd1498Szrj 	   'static' and the global declaration is not visible.
702338fd1498Szrj 	   (If the static declaration _is_ currently visible,
702438fd1498Szrj 	   the 'extern' declaration is taken to refer to that decl.) */
702538fd1498Szrj 	if (extern_ref && current_scope != file_scope)
702638fd1498Szrj 	  {
702738fd1498Szrj 	    tree global_decl  = identifier_global_value (declarator->u.id);
702838fd1498Szrj 	    tree visible_decl = lookup_name (declarator->u.id);
702938fd1498Szrj 
703038fd1498Szrj 	    if (global_decl
703138fd1498Szrj 		&& global_decl != visible_decl
703238fd1498Szrj 		&& VAR_P (global_decl)
703338fd1498Szrj 		&& !TREE_PUBLIC (global_decl))
703438fd1498Szrj 	      error_at (loc, "variable previously declared %<static%> "
703538fd1498Szrj 			"redeclared %<extern%>");
703638fd1498Szrj 	  }
703738fd1498Szrj 
703838fd1498Szrj 	decl = build_decl (declarator->id_loc,
703938fd1498Szrj 			   VAR_DECL, declarator->u.id, type);
704038fd1498Szrj 	if (size_varies)
704138fd1498Szrj 	  C_DECL_VARIABLE_SIZE (decl) = 1;
704238fd1498Szrj 
704338fd1498Szrj 	if (declspecs->inline_p)
704438fd1498Szrj 	  pedwarn (loc, 0, "variable %q+D declared %<inline%>", decl);
704538fd1498Szrj 	if (declspecs->noreturn_p)
704638fd1498Szrj 	  pedwarn (loc, 0, "variable %q+D declared %<_Noreturn%>", decl);
704738fd1498Szrj 
704838fd1498Szrj 	/* At file scope, an initialized extern declaration may follow
704938fd1498Szrj 	   a static declaration.  In that case, DECL_EXTERNAL will be
705038fd1498Szrj 	   reset later in start_decl.  */
705138fd1498Szrj 	DECL_EXTERNAL (decl) = (storage_class == csc_extern);
705238fd1498Szrj 
705338fd1498Szrj 	/* At file scope, the presence of a `static' or `register' storage
705438fd1498Szrj 	   class specifier, or the absence of all storage class specifiers
705538fd1498Szrj 	   makes this declaration a definition (perhaps tentative).  Also,
705638fd1498Szrj 	   the absence of `static' makes it public.  */
705738fd1498Szrj 	if (current_scope == file_scope)
705838fd1498Szrj 	  {
705938fd1498Szrj 	    TREE_PUBLIC (decl) = storage_class != csc_static;
706038fd1498Szrj 	    TREE_STATIC (decl) = !extern_ref;
706138fd1498Szrj 	  }
706238fd1498Szrj 	/* Not at file scope, only `static' makes a static definition.  */
706338fd1498Szrj 	else
706438fd1498Szrj 	  {
706538fd1498Szrj 	    TREE_STATIC (decl) = (storage_class == csc_static);
706638fd1498Szrj 	    TREE_PUBLIC (decl) = extern_ref;
706738fd1498Szrj 	  }
706838fd1498Szrj 
706938fd1498Szrj 	if (threadp)
707038fd1498Szrj 	  set_decl_tls_model (decl, decl_default_tls_model (decl));
707138fd1498Szrj       }
707238fd1498Szrj 
707338fd1498Szrj     if ((storage_class == csc_extern
707438fd1498Szrj 	 || (storage_class == csc_none
707538fd1498Szrj 	     && TREE_CODE (type) == FUNCTION_TYPE
707638fd1498Szrj 	     && !funcdef_flag))
707738fd1498Szrj 	&& variably_modified_type_p (type, NULL_TREE))
707838fd1498Szrj       {
707938fd1498Szrj 	/* C99 6.7.5.2p2 */
708038fd1498Szrj 	if (TREE_CODE (type) == FUNCTION_TYPE)
708138fd1498Szrj 	  error_at (loc, "non-nested function with variably modified type");
708238fd1498Szrj 	else
708338fd1498Szrj 	  error_at (loc, "object with variably modified type must have "
708438fd1498Szrj 	      	    "no linkage");
708538fd1498Szrj       }
708638fd1498Szrj 
708738fd1498Szrj     /* Record `register' declaration for warnings on &
708838fd1498Szrj        and in case doing stupid register allocation.  */
708938fd1498Szrj 
709038fd1498Szrj     if (storage_class == csc_register)
709138fd1498Szrj       {
709238fd1498Szrj 	C_DECL_REGISTER (decl) = 1;
709338fd1498Szrj 	DECL_REGISTER (decl) = 1;
709438fd1498Szrj       }
709538fd1498Szrj 
709638fd1498Szrj     /* Record constancy and volatility.  */
709738fd1498Szrj     c_apply_type_quals_to_decl (type_quals, decl);
709838fd1498Szrj 
709938fd1498Szrj     /* Apply _Alignas specifiers.  */
710038fd1498Szrj     if (alignas_align)
710138fd1498Szrj       {
710238fd1498Szrj 	SET_DECL_ALIGN (decl, alignas_align * BITS_PER_UNIT);
710338fd1498Szrj 	DECL_USER_ALIGN (decl) = 1;
710438fd1498Szrj       }
710538fd1498Szrj 
710638fd1498Szrj     /* If a type has volatile components, it should be stored in memory.
710738fd1498Szrj        Otherwise, the fact that those components are volatile
710838fd1498Szrj        will be ignored, and would even crash the compiler.
710938fd1498Szrj        Of course, this only makes sense on  VAR,PARM, and RESULT decl's.   */
711038fd1498Szrj     if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl))
711138fd1498Szrj 	&& (VAR_P (decl) ||  TREE_CODE (decl) == PARM_DECL
711238fd1498Szrj 	  || TREE_CODE (decl) == RESULT_DECL))
711338fd1498Szrj       {
711438fd1498Szrj 	/* It is not an error for a structure with volatile fields to
711538fd1498Szrj 	   be declared register, but reset DECL_REGISTER since it
711638fd1498Szrj 	   cannot actually go in a register.  */
711738fd1498Szrj 	int was_reg = C_DECL_REGISTER (decl);
711838fd1498Szrj 	C_DECL_REGISTER (decl) = 0;
711938fd1498Szrj 	DECL_REGISTER (decl) = 0;
712038fd1498Szrj 	c_mark_addressable (decl);
712138fd1498Szrj 	C_DECL_REGISTER (decl) = was_reg;
712238fd1498Szrj       }
712338fd1498Szrj 
712438fd1498Szrj   /* This is the earliest point at which we might know the assembler
712538fd1498Szrj      name of a variable.  Thus, if it's known before this, die horribly.  */
712638fd1498Szrj     gcc_assert (!HAS_DECL_ASSEMBLER_NAME_P (decl)
712738fd1498Szrj 		|| !DECL_ASSEMBLER_NAME_SET_P (decl));
712838fd1498Szrj 
712938fd1498Szrj     if (warn_cxx_compat
713038fd1498Szrj 	&& VAR_P (decl)
713138fd1498Szrj 	&& TREE_PUBLIC (decl)
713238fd1498Szrj 	&& TREE_STATIC (decl)
713338fd1498Szrj 	&& (RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl))
713438fd1498Szrj 	    || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
713538fd1498Szrj 	&& TYPE_NAME (TREE_TYPE (decl)) == NULL_TREE)
713638fd1498Szrj       warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
713738fd1498Szrj 		  ("non-local variable %qD with anonymous type is "
713838fd1498Szrj 		   "questionable in C++"),
713938fd1498Szrj 		  decl);
714038fd1498Szrj 
714138fd1498Szrj     return decl;
714238fd1498Szrj   }
714338fd1498Szrj }
714438fd1498Szrj 
714538fd1498Szrj /* Decode the parameter-list info for a function type or function definition.
714638fd1498Szrj    The argument is the value returned by `get_parm_info' (or made in c-parse.c
714738fd1498Szrj    if there is an identifier list instead of a parameter decl list).
714838fd1498Szrj    These two functions are separate because when a function returns
714938fd1498Szrj    or receives functions then each is called multiple times but the order
715038fd1498Szrj    of calls is different.  The last call to `grokparms' is always the one
715138fd1498Szrj    that contains the formal parameter names of a function definition.
715238fd1498Szrj 
715338fd1498Szrj    Return a list of arg types to use in the FUNCTION_TYPE for this function.
715438fd1498Szrj 
715538fd1498Szrj    FUNCDEF_FLAG is true for a function definition, false for
715638fd1498Szrj    a mere declaration.  A nonempty identifier-list gets an error message
715738fd1498Szrj    when FUNCDEF_FLAG is false.  */
715838fd1498Szrj 
715938fd1498Szrj static tree
grokparms(struct c_arg_info * arg_info,bool funcdef_flag)716038fd1498Szrj grokparms (struct c_arg_info *arg_info, bool funcdef_flag)
716138fd1498Szrj {
716238fd1498Szrj   tree arg_types = arg_info->types;
716338fd1498Szrj 
716438fd1498Szrj   if (funcdef_flag && arg_info->had_vla_unspec)
716538fd1498Szrj     {
716638fd1498Szrj       /* A function definition isn't function prototype scope C99 6.2.1p4.  */
716738fd1498Szrj       /* C99 6.7.5.2p4 */
716838fd1498Szrj       error ("%<[*]%> not allowed in other than function prototype scope");
716938fd1498Szrj     }
717038fd1498Szrj 
717138fd1498Szrj   if (arg_types == NULL_TREE && !funcdef_flag
717238fd1498Szrj       && !in_system_header_at (input_location))
717338fd1498Szrj     warning (OPT_Wstrict_prototypes,
717438fd1498Szrj 	     "function declaration isn%'t a prototype");
717538fd1498Szrj 
717638fd1498Szrj   if (arg_types == error_mark_node)
717738fd1498Szrj     /* Don't set TYPE_ARG_TYPES in this case.  */
717838fd1498Szrj     return NULL_TREE;
717938fd1498Szrj 
718038fd1498Szrj   else if (arg_types && TREE_CODE (TREE_VALUE (arg_types)) == IDENTIFIER_NODE)
718138fd1498Szrj     {
718238fd1498Szrj       if (!funcdef_flag)
718338fd1498Szrj 	{
718438fd1498Szrj 	  pedwarn (input_location, 0, "parameter names (without types) in "
718538fd1498Szrj 		   "function declaration");
718638fd1498Szrj 	  arg_info->parms = NULL_TREE;
718738fd1498Szrj 	}
718838fd1498Szrj       else
718938fd1498Szrj 	arg_info->parms = arg_info->types;
719038fd1498Szrj 
719138fd1498Szrj       arg_info->types = NULL_TREE;
719238fd1498Szrj       return NULL_TREE;
719338fd1498Szrj     }
719438fd1498Szrj   else
719538fd1498Szrj     {
719638fd1498Szrj       tree parm, type, typelt;
719738fd1498Szrj       unsigned int parmno;
719838fd1498Szrj 
719938fd1498Szrj       /* If there is a parameter of incomplete type in a definition,
720038fd1498Szrj 	 this is an error.  In a declaration this is valid, and a
720138fd1498Szrj 	 struct or union type may be completed later, before any calls
720238fd1498Szrj 	 or definition of the function.  In the case where the tag was
720338fd1498Szrj 	 first declared within the parameter list, a warning has
720438fd1498Szrj 	 already been given.  If a parameter has void type, then
720538fd1498Szrj 	 however the function cannot be defined or called, so
720638fd1498Szrj 	 warn.  */
720738fd1498Szrj 
720838fd1498Szrj       for (parm = arg_info->parms, typelt = arg_types, parmno = 1;
720938fd1498Szrj 	   parm;
721038fd1498Szrj 	   parm = DECL_CHAIN (parm), typelt = TREE_CHAIN (typelt), parmno++)
721138fd1498Szrj 	{
721238fd1498Szrj 	  type = TREE_VALUE (typelt);
721338fd1498Szrj 	  if (type == error_mark_node)
721438fd1498Szrj 	    continue;
721538fd1498Szrj 
721638fd1498Szrj 	  if (!COMPLETE_TYPE_P (type))
721738fd1498Szrj 	    {
721838fd1498Szrj 	      if (funcdef_flag)
721938fd1498Szrj 		{
722038fd1498Szrj 		  if (DECL_NAME (parm))
722138fd1498Szrj 		    error_at (input_location,
722238fd1498Szrj 			      "parameter %u (%q+D) has incomplete type",
722338fd1498Szrj 			      parmno, parm);
722438fd1498Szrj 		  else
722538fd1498Szrj 		    error_at (DECL_SOURCE_LOCATION (parm),
722638fd1498Szrj 			      "parameter %u has incomplete type",
722738fd1498Szrj 			      parmno);
722838fd1498Szrj 
722938fd1498Szrj 		  TREE_VALUE (typelt) = error_mark_node;
723038fd1498Szrj 		  TREE_TYPE (parm) = error_mark_node;
723138fd1498Szrj 		  arg_types = NULL_TREE;
723238fd1498Szrj 		}
723338fd1498Szrj 	      else if (VOID_TYPE_P (type))
723438fd1498Szrj 		{
723538fd1498Szrj 		  if (DECL_NAME (parm))
723638fd1498Szrj 		    warning_at (input_location, 0,
723738fd1498Szrj 				"parameter %u (%q+D) has void type",
723838fd1498Szrj 				parmno, parm);
723938fd1498Szrj 		  else
724038fd1498Szrj 		    warning_at (DECL_SOURCE_LOCATION (parm), 0,
724138fd1498Szrj 				"parameter %u has void type",
724238fd1498Szrj 				parmno);
724338fd1498Szrj 		}
724438fd1498Szrj 	    }
724538fd1498Szrj 
724638fd1498Szrj 	  if (DECL_NAME (parm) && TREE_USED (parm))
724738fd1498Szrj 	    warn_if_shadowing (parm);
724838fd1498Szrj 	}
724938fd1498Szrj       return arg_types;
725038fd1498Szrj     }
725138fd1498Szrj }
725238fd1498Szrj 
725338fd1498Szrj /* Allocate and initialize a c_arg_info structure from the parser's
725438fd1498Szrj    obstack.  */
725538fd1498Szrj 
725638fd1498Szrj struct c_arg_info *
build_arg_info(void)725738fd1498Szrj build_arg_info (void)
725838fd1498Szrj {
725938fd1498Szrj   struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
726038fd1498Szrj   ret->parms = NULL_TREE;
726138fd1498Szrj   ret->tags = NULL;
726238fd1498Szrj   ret->types = NULL_TREE;
726338fd1498Szrj   ret->others = NULL_TREE;
726438fd1498Szrj   ret->pending_sizes = NULL;
726538fd1498Szrj   ret->had_vla_unspec = 0;
726638fd1498Szrj   return ret;
726738fd1498Szrj }
726838fd1498Szrj 
726938fd1498Szrj /* Take apart the current scope and return a c_arg_info structure with
727038fd1498Szrj    info on a parameter list just parsed.
727138fd1498Szrj 
727238fd1498Szrj    This structure is later fed to 'grokparms' and 'store_parm_decls'.
727338fd1498Szrj 
727438fd1498Szrj    ELLIPSIS being true means the argument list ended in '...' so don't
727538fd1498Szrj    append a sentinel (void_list_node) to the end of the type-list.
727638fd1498Szrj 
727738fd1498Szrj    EXPR is NULL or an expression that needs to be evaluated for the
727838fd1498Szrj    side effects of array size expressions in the parameters.  */
727938fd1498Szrj 
728038fd1498Szrj struct c_arg_info *
get_parm_info(bool ellipsis,tree expr)728138fd1498Szrj get_parm_info (bool ellipsis, tree expr)
728238fd1498Szrj {
728338fd1498Szrj   struct c_binding *b = current_scope->bindings;
728438fd1498Szrj   struct c_arg_info *arg_info = build_arg_info ();
728538fd1498Szrj 
728638fd1498Szrj   tree parms = NULL_TREE;
728738fd1498Szrj   vec<c_arg_tag, va_gc> *tags = NULL;
728838fd1498Szrj   tree types = NULL_TREE;
728938fd1498Szrj   tree others = NULL_TREE;
729038fd1498Szrj 
729138fd1498Szrj   bool gave_void_only_once_err = false;
729238fd1498Szrj 
729338fd1498Szrj   arg_info->had_vla_unspec = current_scope->had_vla_unspec;
729438fd1498Szrj 
729538fd1498Szrj   /* The bindings in this scope must not get put into a block.
729638fd1498Szrj      We will take care of deleting the binding nodes.  */
729738fd1498Szrj   current_scope->bindings = 0;
729838fd1498Szrj 
729938fd1498Szrj   /* This function is only called if there was *something* on the
730038fd1498Szrj      parameter list.  */
730138fd1498Szrj   gcc_assert (b);
730238fd1498Szrj 
730338fd1498Szrj   /* A parameter list consisting solely of 'void' indicates that the
730438fd1498Szrj      function takes no arguments.  But if the 'void' is qualified
730538fd1498Szrj      (by 'const' or 'volatile'), or has a storage class specifier
730638fd1498Szrj      ('register'), then the behavior is undefined; issue an error.
730738fd1498Szrj      Typedefs for 'void' are OK (see DR#157).  */
730838fd1498Szrj   if (b->prev == 0			    /* one binding */
730938fd1498Szrj       && TREE_CODE (b->decl) == PARM_DECL   /* which is a parameter */
731038fd1498Szrj       && !DECL_NAME (b->decl)               /* anonymous */
731138fd1498Szrj       && VOID_TYPE_P (TREE_TYPE (b->decl))) /* of void type */
731238fd1498Szrj     {
731338fd1498Szrj       if (TYPE_QUALS (TREE_TYPE (b->decl)) != TYPE_UNQUALIFIED
731438fd1498Szrj 	  || C_DECL_REGISTER (b->decl))
731538fd1498Szrj 	error_at (b->locus, "%<void%> as only parameter may not be qualified");
731638fd1498Szrj 
731738fd1498Szrj       /* There cannot be an ellipsis.  */
731838fd1498Szrj       if (ellipsis)
731938fd1498Szrj 	error_at (b->locus, "%<void%> must be the only parameter");
732038fd1498Szrj 
732138fd1498Szrj       arg_info->types = void_list_node;
732238fd1498Szrj       return arg_info;
732338fd1498Szrj     }
732438fd1498Szrj 
732538fd1498Szrj   if (!ellipsis)
732638fd1498Szrj     types = void_list_node;
732738fd1498Szrj 
732838fd1498Szrj   /* Break up the bindings list into parms, tags, types, and others;
732938fd1498Szrj      apply sanity checks; purge the name-to-decl bindings.  */
733038fd1498Szrj   while (b)
733138fd1498Szrj     {
733238fd1498Szrj       tree decl = b->decl;
733338fd1498Szrj       tree type = TREE_TYPE (decl);
733438fd1498Szrj       c_arg_tag tag;
733538fd1498Szrj       const char *keyword;
733638fd1498Szrj 
733738fd1498Szrj       switch (TREE_CODE (decl))
733838fd1498Szrj 	{
733938fd1498Szrj 	case PARM_DECL:
734038fd1498Szrj 	  if (b->id)
734138fd1498Szrj 	    {
734238fd1498Szrj 	      gcc_assert (I_SYMBOL_BINDING (b->id) == b);
734338fd1498Szrj 	      I_SYMBOL_BINDING (b->id) = b->shadowed;
734438fd1498Szrj 	    }
734538fd1498Szrj 
734638fd1498Szrj 	  /* Check for forward decls that never got their actual decl.  */
734738fd1498Szrj 	  if (TREE_ASM_WRITTEN (decl))
734838fd1498Szrj 	    error_at (b->locus,
734938fd1498Szrj 		      "parameter %q+D has just a forward declaration", decl);
735038fd1498Szrj 	  /* Check for (..., void, ...) and issue an error.  */
735138fd1498Szrj 	  else if (VOID_TYPE_P (type) && !DECL_NAME (decl))
735238fd1498Szrj 	    {
735338fd1498Szrj 	      if (!gave_void_only_once_err)
735438fd1498Szrj 		{
735538fd1498Szrj 		  error_at (b->locus, "%<void%> must be the only parameter");
735638fd1498Szrj 		  gave_void_only_once_err = true;
735738fd1498Szrj 		}
735838fd1498Szrj 	    }
735938fd1498Szrj 	  else
736038fd1498Szrj 	    {
736138fd1498Szrj 	      /* Valid parameter, add it to the list.  */
736238fd1498Szrj 	      DECL_CHAIN (decl) = parms;
736338fd1498Szrj 	      parms = decl;
736438fd1498Szrj 
736538fd1498Szrj 	      /* Since there is a prototype, args are passed in their
736638fd1498Szrj 		 declared types.  The back end may override this later.  */
736738fd1498Szrj 	      DECL_ARG_TYPE (decl) = type;
736838fd1498Szrj 	      types = tree_cons (0, type, types);
736938fd1498Szrj 	    }
737038fd1498Szrj 	  break;
737138fd1498Szrj 
737238fd1498Szrj 	case ENUMERAL_TYPE: keyword = "enum"; goto tag;
737338fd1498Szrj 	case UNION_TYPE:    keyword = "union"; goto tag;
737438fd1498Szrj 	case RECORD_TYPE:   keyword = "struct"; goto tag;
737538fd1498Szrj 	tag:
737638fd1498Szrj 	  /* Types may not have tag-names, in which case the type
737738fd1498Szrj 	     appears in the bindings list with b->id NULL.  */
737838fd1498Szrj 	  if (b->id)
737938fd1498Szrj 	    {
738038fd1498Szrj 	      gcc_assert (I_TAG_BINDING (b->id) == b);
738138fd1498Szrj 	      I_TAG_BINDING (b->id) = b->shadowed;
738238fd1498Szrj 	    }
738338fd1498Szrj 
738438fd1498Szrj 	  /* Warn about any struct, union or enum tags defined in a
738538fd1498Szrj 	     parameter list.  The scope of such types is limited to
738638fd1498Szrj 	     the parameter list, which is rarely if ever desirable
738738fd1498Szrj 	     (it's impossible to call such a function with type-
738838fd1498Szrj 	     correct arguments).  An anonymous union parm type is
738938fd1498Szrj 	     meaningful as a GNU extension, so don't warn for that.  */
739038fd1498Szrj 	  if (TREE_CODE (decl) != UNION_TYPE || b->id != NULL_TREE)
739138fd1498Szrj 	    {
739238fd1498Szrj 	      if (b->id)
739338fd1498Szrj 		/* The %s will be one of 'struct', 'union', or 'enum'.  */
739438fd1498Szrj 		warning_at (b->locus, 0,
739538fd1498Szrj 			    "%<%s %E%> declared inside parameter list"
739638fd1498Szrj 			    " will not be visible outside of this definition or"
739738fd1498Szrj 			    " declaration", keyword, b->id);
739838fd1498Szrj 	      else
739938fd1498Szrj 		/* The %s will be one of 'struct', 'union', or 'enum'.  */
740038fd1498Szrj 		warning_at (b->locus, 0,
740138fd1498Szrj 			    "anonymous %s declared inside parameter list"
740238fd1498Szrj 			    " will not be visible outside of this definition or"
740338fd1498Szrj 			    " declaration", keyword);
740438fd1498Szrj 	    }
740538fd1498Szrj 
740638fd1498Szrj 	  tag.id = b->id;
740738fd1498Szrj 	  tag.type = decl;
740838fd1498Szrj 	  vec_safe_push (tags, tag);
740938fd1498Szrj 	  break;
741038fd1498Szrj 
741138fd1498Szrj 	case FUNCTION_DECL:
741238fd1498Szrj 	  /* FUNCTION_DECLs appear when there is an implicit function
741338fd1498Szrj 	     declaration in the parameter list.  */
741438fd1498Szrj 	  gcc_assert (b->nested || seen_error ());
741538fd1498Szrj 	  goto set_shadowed;
741638fd1498Szrj 
741738fd1498Szrj 	case CONST_DECL:
741838fd1498Szrj 	case TYPE_DECL:
741938fd1498Szrj 	  /* CONST_DECLs appear here when we have an embedded enum,
742038fd1498Szrj 	     and TYPE_DECLs appear here when we have an embedded struct
742138fd1498Szrj 	     or union.  No warnings for this - we already warned about the
742238fd1498Szrj 	     type itself.  */
742338fd1498Szrj 
742438fd1498Szrj 	  /* When we reinsert this decl in the function body, we need
742538fd1498Szrj 	     to reconstruct whether it was marked as nested.  */
742638fd1498Szrj 	  gcc_assert (!b->nested);
742738fd1498Szrj 	  DECL_CHAIN (decl) = others;
742838fd1498Szrj 	  others = decl;
742938fd1498Szrj 	  /* fall through */
743038fd1498Szrj 
743138fd1498Szrj 	case ERROR_MARK:
743238fd1498Szrj 	set_shadowed:
743338fd1498Szrj 	  /* error_mark_node appears here when we have an undeclared
743438fd1498Szrj 	     variable.  Just throw it away.  */
743538fd1498Szrj 	  if (b->id)
743638fd1498Szrj 	    {
743738fd1498Szrj 	      gcc_assert (I_SYMBOL_BINDING (b->id) == b);
743838fd1498Szrj 	      I_SYMBOL_BINDING (b->id) = b->shadowed;
743938fd1498Szrj 	    }
744038fd1498Szrj 	  break;
744138fd1498Szrj 
744238fd1498Szrj 	  /* Other things that might be encountered.  */
744338fd1498Szrj 	case LABEL_DECL:
744438fd1498Szrj 	case VAR_DECL:
744538fd1498Szrj 	default:
744638fd1498Szrj 	  gcc_unreachable ();
744738fd1498Szrj 	}
744838fd1498Szrj 
744938fd1498Szrj       b = free_binding_and_advance (b);
745038fd1498Szrj     }
745138fd1498Szrj 
745238fd1498Szrj   arg_info->parms = parms;
745338fd1498Szrj   arg_info->tags = tags;
745438fd1498Szrj   arg_info->types = types;
745538fd1498Szrj   arg_info->others = others;
745638fd1498Szrj   arg_info->pending_sizes = expr;
745738fd1498Szrj   return arg_info;
745838fd1498Szrj }
745938fd1498Szrj 
746038fd1498Szrj /* Get the struct, enum or union (CODE says which) with tag NAME.
746138fd1498Szrj    Define the tag as a forward-reference with location LOC if it is
746238fd1498Szrj    not defined.  Return a c_typespec structure for the type
746338fd1498Szrj    specifier.  */
746438fd1498Szrj 
746538fd1498Szrj struct c_typespec
parser_xref_tag(location_t loc,enum tree_code code,tree name)746638fd1498Szrj parser_xref_tag (location_t loc, enum tree_code code, tree name)
746738fd1498Szrj {
746838fd1498Szrj   struct c_typespec ret;
746938fd1498Szrj   tree ref;
747038fd1498Szrj   location_t refloc;
747138fd1498Szrj 
747238fd1498Szrj   ret.expr = NULL_TREE;
747338fd1498Szrj   ret.expr_const_operands = true;
747438fd1498Szrj 
747538fd1498Szrj   /* If a cross reference is requested, look up the type
747638fd1498Szrj      already defined for this tag and return it.  */
747738fd1498Szrj 
747838fd1498Szrj   ref = lookup_tag (code, name, false, &refloc);
747938fd1498Szrj   /* If this is the right type of tag, return what we found.
748038fd1498Szrj      (This reference will be shadowed by shadow_tag later if appropriate.)
748138fd1498Szrj      If this is the wrong type of tag, do not return it.  If it was the
748238fd1498Szrj      wrong type in the same scope, we will have had an error
748338fd1498Szrj      message already; if in a different scope and declaring
748438fd1498Szrj      a name, pending_xref_error will give an error message; but if in a
748538fd1498Szrj      different scope and not declaring a name, this tag should
748638fd1498Szrj      shadow the previous declaration of a different type of tag, and
748738fd1498Szrj      this would not work properly if we return the reference found.
748838fd1498Szrj      (For example, with "struct foo" in an outer scope, "union foo;"
748938fd1498Szrj      must shadow that tag with a new one of union type.)  */
749038fd1498Szrj   ret.kind = (ref ? ctsk_tagref : ctsk_tagfirstref);
749138fd1498Szrj   if (ref && TREE_CODE (ref) == code)
749238fd1498Szrj     {
749338fd1498Szrj       if (C_TYPE_DEFINED_IN_STRUCT (ref)
749438fd1498Szrj 	  && loc != UNKNOWN_LOCATION
749538fd1498Szrj 	  && warn_cxx_compat)
749638fd1498Szrj 	{
749738fd1498Szrj 	  switch (code)
749838fd1498Szrj 	    {
749938fd1498Szrj 	    case ENUMERAL_TYPE:
750038fd1498Szrj 	      warning_at (loc, OPT_Wc___compat,
750138fd1498Szrj 			  ("enum type defined in struct or union "
750238fd1498Szrj 			   "is not visible in C++"));
750338fd1498Szrj 	      inform (refloc, "enum type defined here");
750438fd1498Szrj 	      break;
750538fd1498Szrj 	    case RECORD_TYPE:
750638fd1498Szrj 	      warning_at (loc, OPT_Wc___compat,
750738fd1498Szrj 			  ("struct defined in struct or union "
750838fd1498Szrj 			   "is not visible in C++"));
750938fd1498Szrj 	      inform (refloc, "struct defined here");
751038fd1498Szrj 	      break;
751138fd1498Szrj 	    case UNION_TYPE:
751238fd1498Szrj 	      warning_at (loc, OPT_Wc___compat,
751338fd1498Szrj 			  ("union defined in struct or union "
751438fd1498Szrj 			   "is not visible in C++"));
751538fd1498Szrj 	      inform (refloc, "union defined here");
751638fd1498Szrj 	      break;
751738fd1498Szrj 	    default:
751838fd1498Szrj 	      gcc_unreachable();
751938fd1498Szrj 	    }
752038fd1498Szrj 	}
752138fd1498Szrj 
752238fd1498Szrj       ret.spec = ref;
752338fd1498Szrj       return ret;
752438fd1498Szrj     }
752538fd1498Szrj 
752638fd1498Szrj   /* If no such tag is yet defined, create a forward-reference node
752738fd1498Szrj      and record it as the "definition".
752838fd1498Szrj      When a real declaration of this type is found,
752938fd1498Szrj      the forward-reference will be altered into a real type.  */
753038fd1498Szrj 
753138fd1498Szrj   ref = make_node (code);
753238fd1498Szrj   if (code == ENUMERAL_TYPE)
753338fd1498Szrj     {
753438fd1498Szrj       /* Give the type a default layout like unsigned int
753538fd1498Szrj 	 to avoid crashing if it does not get defined.  */
753638fd1498Szrj       SET_TYPE_MODE (ref, TYPE_MODE (unsigned_type_node));
753738fd1498Szrj       SET_TYPE_ALIGN (ref, TYPE_ALIGN (unsigned_type_node));
753838fd1498Szrj       TYPE_USER_ALIGN (ref) = 0;
753938fd1498Szrj       TYPE_UNSIGNED (ref) = 1;
754038fd1498Szrj       TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
754138fd1498Szrj       TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
754238fd1498Szrj       TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
754338fd1498Szrj     }
754438fd1498Szrj 
754538fd1498Szrj   pushtag (loc, name, ref);
754638fd1498Szrj 
754738fd1498Szrj   ret.spec = ref;
754838fd1498Szrj   return ret;
754938fd1498Szrj }
755038fd1498Szrj 
755138fd1498Szrj /* Get the struct, enum or union (CODE says which) with tag NAME.
755238fd1498Szrj    Define the tag as a forward-reference if it is not defined.
755338fd1498Szrj    Return a tree for the type.  */
755438fd1498Szrj 
755538fd1498Szrj tree
xref_tag(enum tree_code code,tree name)755638fd1498Szrj xref_tag (enum tree_code code, tree name)
755738fd1498Szrj {
755838fd1498Szrj   return parser_xref_tag (input_location, code, name).spec;
755938fd1498Szrj }
756038fd1498Szrj 
756138fd1498Szrj /* Make sure that the tag NAME is defined *in the current scope*
756238fd1498Szrj    at least as a forward reference.
756338fd1498Szrj    LOC is the location of the struct's definition.
756438fd1498Szrj    CODE says which kind of tag NAME ought to be.
756538fd1498Szrj 
756638fd1498Szrj    This stores the current value of the file static STRUCT_PARSE_INFO
756738fd1498Szrj    in *ENCLOSING_STRUCT_PARSE_INFO, and points STRUCT_PARSE_INFO at a
756838fd1498Szrj    new c_struct_parse_info structure.  The old value of
756938fd1498Szrj    STRUCT_PARSE_INFO is restored in finish_struct.  */
757038fd1498Szrj 
757138fd1498Szrj tree
start_struct(location_t loc,enum tree_code code,tree name,struct c_struct_parse_info ** enclosing_struct_parse_info)757238fd1498Szrj start_struct (location_t loc, enum tree_code code, tree name,
757338fd1498Szrj 	      struct c_struct_parse_info **enclosing_struct_parse_info)
757438fd1498Szrj {
757538fd1498Szrj   /* If there is already a tag defined at this scope
757638fd1498Szrj      (as a forward reference), just return it.  */
757738fd1498Szrj 
757838fd1498Szrj   tree ref = NULL_TREE;
757938fd1498Szrj   location_t refloc = UNKNOWN_LOCATION;
758038fd1498Szrj 
758138fd1498Szrj   if (name != NULL_TREE)
758238fd1498Szrj     ref = lookup_tag (code, name, true, &refloc);
758338fd1498Szrj   if (ref && TREE_CODE (ref) == code)
758438fd1498Szrj     {
758538fd1498Szrj       if (TYPE_STUB_DECL (ref))
758638fd1498Szrj 	refloc = DECL_SOURCE_LOCATION (TYPE_STUB_DECL (ref));
758738fd1498Szrj 
758838fd1498Szrj       if (TYPE_SIZE (ref))
758938fd1498Szrj 	{
759038fd1498Szrj 	  if (code == UNION_TYPE)
759138fd1498Szrj 	    error_at (loc, "redefinition of %<union %E%>", name);
759238fd1498Szrj 	  else
759338fd1498Szrj 	    error_at (loc, "redefinition of %<struct %E%>", name);
759438fd1498Szrj 	  if (refloc != UNKNOWN_LOCATION)
759538fd1498Szrj 	    inform (refloc, "originally defined here");
759638fd1498Szrj 	  /* Don't create structures using a name already in use.  */
759738fd1498Szrj 	  ref = NULL_TREE;
759838fd1498Szrj 	}
759938fd1498Szrj       else if (C_TYPE_BEING_DEFINED (ref))
760038fd1498Szrj 	{
760138fd1498Szrj 	  if (code == UNION_TYPE)
760238fd1498Szrj 	    error_at (loc, "nested redefinition of %<union %E%>", name);
760338fd1498Szrj 	  else
760438fd1498Szrj 	    error_at (loc, "nested redefinition of %<struct %E%>", name);
760538fd1498Szrj 	  /* Don't bother to report "originally defined here" for a
760638fd1498Szrj 	     nested redefinition; the original definition should be
760738fd1498Szrj 	     obvious.  */
760838fd1498Szrj 	  /* Don't create structures that contain themselves.  */
760938fd1498Szrj 	  ref = NULL_TREE;
761038fd1498Szrj 	}
761138fd1498Szrj     }
761238fd1498Szrj 
761338fd1498Szrj   /* Otherwise create a forward-reference just so the tag is in scope.  */
761438fd1498Szrj 
761538fd1498Szrj   if (ref == NULL_TREE || TREE_CODE (ref) != code)
761638fd1498Szrj     {
761738fd1498Szrj       ref = make_node (code);
761838fd1498Szrj       pushtag (loc, name, ref);
761938fd1498Szrj     }
762038fd1498Szrj 
762138fd1498Szrj   C_TYPE_BEING_DEFINED (ref) = 1;
762238fd1498Szrj   for (tree v = TYPE_MAIN_VARIANT (ref); v; v = TYPE_NEXT_VARIANT (v))
762338fd1498Szrj     TYPE_PACKED (v) = flag_pack_struct;
762438fd1498Szrj 
762538fd1498Szrj   *enclosing_struct_parse_info = struct_parse_info;
762638fd1498Szrj   struct_parse_info = new c_struct_parse_info ();
762738fd1498Szrj 
762838fd1498Szrj   /* FIXME: This will issue a warning for a use of a type defined
762938fd1498Szrj      within a statement expr used within sizeof, et. al.  This is not
763038fd1498Szrj      terribly serious as C++ doesn't permit statement exprs within
763138fd1498Szrj      sizeof anyhow.  */
763238fd1498Szrj   if (warn_cxx_compat && (in_sizeof || in_typeof || in_alignof))
763338fd1498Szrj     warning_at (loc, OPT_Wc___compat,
763438fd1498Szrj 		"defining type in %qs expression is invalid in C++",
763538fd1498Szrj 		(in_sizeof
763638fd1498Szrj 		 ? "sizeof"
763738fd1498Szrj 		 : (in_typeof ? "typeof" : "alignof")));
763838fd1498Szrj 
763938fd1498Szrj   return ref;
764038fd1498Szrj }
764138fd1498Szrj 
764238fd1498Szrj /* Process the specs, declarator and width (NULL if omitted)
764338fd1498Szrj    of a structure component, returning a FIELD_DECL node.
764438fd1498Szrj    WIDTH is non-NULL for bit-fields only, and is an INTEGER_CST node.
764538fd1498Szrj    DECL_ATTRS is as for grokdeclarator.
764638fd1498Szrj 
764738fd1498Szrj    LOC is the location of the structure component.
764838fd1498Szrj 
764938fd1498Szrj    This is done during the parsing of the struct declaration.
765038fd1498Szrj    The FIELD_DECL nodes are chained together and the lot of them
765138fd1498Szrj    are ultimately passed to `build_struct' to make the RECORD_TYPE node.  */
765238fd1498Szrj 
765338fd1498Szrj tree
grokfield(location_t loc,struct c_declarator * declarator,struct c_declspecs * declspecs,tree width,tree * decl_attrs)765438fd1498Szrj grokfield (location_t loc,
765538fd1498Szrj 	   struct c_declarator *declarator, struct c_declspecs *declspecs,
765638fd1498Szrj 	   tree width, tree *decl_attrs)
765738fd1498Szrj {
765838fd1498Szrj   tree value;
765938fd1498Szrj 
766038fd1498Szrj   if (declarator->kind == cdk_id && declarator->u.id == NULL_TREE
766138fd1498Szrj       && width == NULL_TREE)
766238fd1498Szrj     {
766338fd1498Szrj       /* This is an unnamed decl.
766438fd1498Szrj 
766538fd1498Szrj 	 If we have something of the form "union { list } ;" then this
766638fd1498Szrj 	 is the anonymous union extension.  Similarly for struct.
766738fd1498Szrj 
766838fd1498Szrj 	 If this is something of the form "struct foo;", then
766938fd1498Szrj 	   If MS or Plan 9 extensions are enabled, this is handled as
767038fd1498Szrj 	     an anonymous struct.
767138fd1498Szrj 	   Otherwise this is a forward declaration of a structure tag.
767238fd1498Szrj 
767338fd1498Szrj 	 If this is something of the form "foo;" and foo is a TYPE_DECL, then
767438fd1498Szrj 	   If foo names a structure or union without a tag, then this
767538fd1498Szrj 	     is an anonymous struct (this is permitted by C11).
767638fd1498Szrj 	   If MS or Plan 9 extensions are enabled and foo names a
767738fd1498Szrj 	     structure, then again this is an anonymous struct.
767838fd1498Szrj 	   Otherwise this is an error.
767938fd1498Szrj 
768038fd1498Szrj 	 Oh what a horrid tangled web we weave.  I wonder if MS consciously
768138fd1498Szrj 	 took this from Plan 9 or if it was an accident of implementation
768238fd1498Szrj 	 that took root before someone noticed the bug...  */
768338fd1498Szrj 
768438fd1498Szrj       tree type = declspecs->type;
768538fd1498Szrj       bool ok = false;
768638fd1498Szrj 
768738fd1498Szrj       if (RECORD_OR_UNION_TYPE_P (type)
768838fd1498Szrj 	  && (flag_ms_extensions
768938fd1498Szrj 	      || flag_plan9_extensions
769038fd1498Szrj 	      || !declspecs->typedef_p))
769138fd1498Szrj 	{
769238fd1498Szrj 	  if (flag_ms_extensions || flag_plan9_extensions)
769338fd1498Szrj 	    ok = true;
769438fd1498Szrj 	  else if (TYPE_NAME (type) == NULL)
769538fd1498Szrj 	    ok = true;
769638fd1498Szrj 	  else
769738fd1498Szrj 	    ok = false;
769838fd1498Szrj 	}
769938fd1498Szrj       if (!ok)
770038fd1498Szrj 	{
770138fd1498Szrj 	  pedwarn (loc, 0, "declaration does not declare anything");
770238fd1498Szrj 	  return NULL_TREE;
770338fd1498Szrj 	}
770438fd1498Szrj       if (flag_isoc99)
770538fd1498Szrj 	pedwarn_c99 (loc, OPT_Wpedantic,
770638fd1498Szrj 		     "ISO C99 doesn%'t support unnamed structs/unions");
770738fd1498Szrj       else
770838fd1498Szrj 	pedwarn_c99 (loc, OPT_Wpedantic,
770938fd1498Szrj 		     "ISO C90 doesn%'t support unnamed structs/unions");
771038fd1498Szrj     }
771138fd1498Szrj 
771238fd1498Szrj   value = grokdeclarator (declarator, declspecs, FIELD, false,
771338fd1498Szrj 			  width ? &width : NULL, decl_attrs, NULL, NULL,
771438fd1498Szrj 			  DEPRECATED_NORMAL);
771538fd1498Szrj 
771638fd1498Szrj   finish_decl (value, loc, NULL_TREE, NULL_TREE, NULL_TREE);
771738fd1498Szrj   DECL_INITIAL (value) = width;
771838fd1498Szrj   if (width)
771938fd1498Szrj     SET_DECL_C_BIT_FIELD (value);
772038fd1498Szrj 
772138fd1498Szrj   if (warn_cxx_compat && DECL_NAME (value) != NULL_TREE)
772238fd1498Szrj     {
772338fd1498Szrj       /* If we currently have a binding for this field, set the
772438fd1498Szrj 	 in_struct field in the binding, so that we warn about lookups
772538fd1498Szrj 	 which find it.  */
772638fd1498Szrj       struct c_binding *b = I_SYMBOL_BINDING (DECL_NAME (value));
772738fd1498Szrj       if (b != NULL)
772838fd1498Szrj 	{
772938fd1498Szrj 	  /* If the in_struct field is not yet set, push it on a list
773038fd1498Szrj 	     to be cleared when this struct is finished.  */
773138fd1498Szrj 	  if (!b->in_struct)
773238fd1498Szrj 	    {
773338fd1498Szrj 	      struct_parse_info->fields.safe_push (b);
773438fd1498Szrj 	      b->in_struct = 1;
773538fd1498Szrj 	    }
773638fd1498Szrj 	}
773738fd1498Szrj     }
773838fd1498Szrj 
773938fd1498Szrj   return value;
774038fd1498Szrj }
774138fd1498Szrj 
774238fd1498Szrj /* Subroutine of detect_field_duplicates: return whether X and Y,
774338fd1498Szrj    which are both fields in the same struct, have duplicate field
774438fd1498Szrj    names.  */
774538fd1498Szrj 
774638fd1498Szrj static bool
is_duplicate_field(tree x,tree y)774738fd1498Szrj is_duplicate_field (tree x, tree y)
774838fd1498Szrj {
774938fd1498Szrj   if (DECL_NAME (x) != NULL_TREE && DECL_NAME (x) == DECL_NAME (y))
775038fd1498Szrj     return true;
775138fd1498Szrj 
775238fd1498Szrj   /* When using -fplan9-extensions, an anonymous field whose name is a
775338fd1498Szrj      typedef can duplicate a field name.  */
775438fd1498Szrj   if (flag_plan9_extensions
775538fd1498Szrj       && (DECL_NAME (x) == NULL_TREE || DECL_NAME (y) == NULL_TREE))
775638fd1498Szrj     {
775738fd1498Szrj       tree xt, xn, yt, yn;
775838fd1498Szrj 
775938fd1498Szrj       xt = TREE_TYPE (x);
776038fd1498Szrj       if (DECL_NAME (x) != NULL_TREE)
776138fd1498Szrj 	xn = DECL_NAME (x);
776238fd1498Szrj       else if (RECORD_OR_UNION_TYPE_P (xt)
776338fd1498Szrj 	       && TYPE_NAME (xt) != NULL_TREE
776438fd1498Szrj 	       && TREE_CODE (TYPE_NAME (xt)) == TYPE_DECL)
776538fd1498Szrj 	xn = DECL_NAME (TYPE_NAME (xt));
776638fd1498Szrj       else
776738fd1498Szrj 	xn = NULL_TREE;
776838fd1498Szrj 
776938fd1498Szrj       yt = TREE_TYPE (y);
777038fd1498Szrj       if (DECL_NAME (y) != NULL_TREE)
777138fd1498Szrj 	yn = DECL_NAME (y);
777238fd1498Szrj       else if (RECORD_OR_UNION_TYPE_P (yt)
777338fd1498Szrj 	       && TYPE_NAME (yt) != NULL_TREE
777438fd1498Szrj 	       && TREE_CODE (TYPE_NAME (yt)) == TYPE_DECL)
777538fd1498Szrj 	yn = DECL_NAME (TYPE_NAME (yt));
777638fd1498Szrj       else
777738fd1498Szrj 	yn = NULL_TREE;
777838fd1498Szrj 
777938fd1498Szrj       if (xn != NULL_TREE && xn == yn)
778038fd1498Szrj 	return true;
778138fd1498Szrj     }
778238fd1498Szrj 
778338fd1498Szrj   return false;
778438fd1498Szrj }
778538fd1498Szrj 
778638fd1498Szrj /* Subroutine of detect_field_duplicates: add the fields of FIELDLIST
778738fd1498Szrj    to HTAB, giving errors for any duplicates.  */
778838fd1498Szrj 
778938fd1498Szrj static void
detect_field_duplicates_hash(tree fieldlist,hash_table<nofree_ptr_hash<tree_node>> * htab)779038fd1498Szrj detect_field_duplicates_hash (tree fieldlist,
779138fd1498Szrj 			      hash_table<nofree_ptr_hash <tree_node> > *htab)
779238fd1498Szrj {
779338fd1498Szrj   tree x, y;
779438fd1498Szrj   tree_node **slot;
779538fd1498Szrj 
779638fd1498Szrj   for (x = fieldlist; x ; x = DECL_CHAIN (x))
779738fd1498Szrj     if ((y = DECL_NAME (x)) != NULL_TREE)
779838fd1498Szrj       {
779938fd1498Szrj 	slot = htab->find_slot (y, INSERT);
780038fd1498Szrj 	if (*slot)
780138fd1498Szrj 	  {
780238fd1498Szrj 	    error ("duplicate member %q+D", x);
780338fd1498Szrj 	    DECL_NAME (x) = NULL_TREE;
780438fd1498Szrj 	  }
780538fd1498Szrj 	*slot = y;
780638fd1498Szrj       }
780738fd1498Szrj     else if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (x)))
780838fd1498Szrj       {
780938fd1498Szrj 	detect_field_duplicates_hash (TYPE_FIELDS (TREE_TYPE (x)), htab);
781038fd1498Szrj 
781138fd1498Szrj 	/* When using -fplan9-extensions, an anonymous field whose
781238fd1498Szrj 	   name is a typedef can duplicate a field name.  */
781338fd1498Szrj 	if (flag_plan9_extensions
781438fd1498Szrj 	    && TYPE_NAME (TREE_TYPE (x)) != NULL_TREE
781538fd1498Szrj 	    && TREE_CODE (TYPE_NAME (TREE_TYPE (x))) == TYPE_DECL)
781638fd1498Szrj 	  {
781738fd1498Szrj 	    tree xn = DECL_NAME (TYPE_NAME (TREE_TYPE (x)));
781838fd1498Szrj 	    slot = htab->find_slot (xn, INSERT);
781938fd1498Szrj 	    if (*slot)
782038fd1498Szrj 	      error ("duplicate member %q+D", TYPE_NAME (TREE_TYPE (x)));
782138fd1498Szrj 	    *slot = xn;
782238fd1498Szrj 	  }
782338fd1498Szrj       }
782438fd1498Szrj }
782538fd1498Szrj 
782638fd1498Szrj /* Generate an error for any duplicate field names in FIELDLIST.  Munge
782738fd1498Szrj    the list such that this does not present a problem later.  */
782838fd1498Szrj 
782938fd1498Szrj static void
detect_field_duplicates(tree fieldlist)783038fd1498Szrj detect_field_duplicates (tree fieldlist)
783138fd1498Szrj {
783238fd1498Szrj   tree x, y;
783338fd1498Szrj   int timeout = 10;
783438fd1498Szrj 
783538fd1498Szrj   /* If the struct is the list of instance variables of an Objective-C
783638fd1498Szrj      class, then we need to check all the instance variables of
783738fd1498Szrj      superclasses when checking for duplicates (since you can't have
783838fd1498Szrj      an instance variable in a subclass with the same name as an
783938fd1498Szrj      instance variable in a superclass).  We pass on this job to the
784038fd1498Szrj      Objective-C compiler.  objc_detect_field_duplicates() will return
784138fd1498Szrj      false if we are not checking the list of instance variables and
784238fd1498Szrj      the C frontend should proceed with the standard field duplicate
784338fd1498Szrj      checks.  If we are checking the list of instance variables, the
784438fd1498Szrj      ObjC frontend will do the check, emit the errors if needed, and
784538fd1498Szrj      then return true.  */
784638fd1498Szrj   if (c_dialect_objc ())
784738fd1498Szrj     if (objc_detect_field_duplicates (false))
784838fd1498Szrj       return;
784938fd1498Szrj 
785038fd1498Szrj   /* First, see if there are more than "a few" fields.
785138fd1498Szrj      This is trivially true if there are zero or one fields.  */
785238fd1498Szrj   if (!fieldlist || !DECL_CHAIN (fieldlist))
785338fd1498Szrj     return;
785438fd1498Szrj   x = fieldlist;
785538fd1498Szrj   do {
785638fd1498Szrj     timeout--;
785738fd1498Szrj     if (DECL_NAME (x) == NULL_TREE
785838fd1498Szrj 	&& RECORD_OR_UNION_TYPE_P (TREE_TYPE (x)))
785938fd1498Szrj       timeout = 0;
786038fd1498Szrj     x = DECL_CHAIN (x);
786138fd1498Szrj   } while (timeout > 0 && x);
786238fd1498Szrj 
786338fd1498Szrj   /* If there were "few" fields and no anonymous structures or unions,
786438fd1498Szrj      avoid the overhead of allocating a hash table.  Instead just do
786538fd1498Szrj      the nested traversal thing.  */
786638fd1498Szrj   if (timeout > 0)
786738fd1498Szrj     {
786838fd1498Szrj       for (x = DECL_CHAIN (fieldlist); x; x = DECL_CHAIN (x))
786938fd1498Szrj 	/* When using -fplan9-extensions, we can have duplicates
787038fd1498Szrj 	   between typedef names and fields.  */
787138fd1498Szrj 	if (DECL_NAME (x)
787238fd1498Szrj 	    || (flag_plan9_extensions
787338fd1498Szrj 		&& DECL_NAME (x) == NULL_TREE
787438fd1498Szrj 		&& RECORD_OR_UNION_TYPE_P (TREE_TYPE (x))
787538fd1498Szrj 		&& TYPE_NAME (TREE_TYPE (x)) != NULL_TREE
787638fd1498Szrj 		&& TREE_CODE (TYPE_NAME (TREE_TYPE (x))) == TYPE_DECL))
787738fd1498Szrj 	  {
787838fd1498Szrj 	    for (y = fieldlist; y != x; y = TREE_CHAIN (y))
787938fd1498Szrj 	      if (is_duplicate_field (y, x))
788038fd1498Szrj 		{
788138fd1498Szrj 		  error ("duplicate member %q+D", x);
788238fd1498Szrj 		  DECL_NAME (x) = NULL_TREE;
788338fd1498Szrj 		}
788438fd1498Szrj 	  }
788538fd1498Szrj     }
788638fd1498Szrj   else
788738fd1498Szrj     {
788838fd1498Szrj       hash_table<nofree_ptr_hash <tree_node> > htab (37);
788938fd1498Szrj       detect_field_duplicates_hash (fieldlist, &htab);
789038fd1498Szrj     }
789138fd1498Szrj }
789238fd1498Szrj 
789338fd1498Szrj /* Finish up struct info used by -Wc++-compat.  */
789438fd1498Szrj 
789538fd1498Szrj static void
warn_cxx_compat_finish_struct(tree fieldlist,enum tree_code code,location_t record_loc)789638fd1498Szrj warn_cxx_compat_finish_struct (tree fieldlist, enum tree_code code,
789738fd1498Szrj 			       location_t record_loc)
789838fd1498Szrj {
789938fd1498Szrj   unsigned int ix;
790038fd1498Szrj   tree x;
790138fd1498Szrj   struct c_binding *b;
790238fd1498Szrj 
790338fd1498Szrj   if (fieldlist == NULL_TREE)
790438fd1498Szrj     {
790538fd1498Szrj       if (code == RECORD_TYPE)
790638fd1498Szrj 	warning_at (record_loc, OPT_Wc___compat,
790738fd1498Szrj 		    "empty struct has size 0 in C, size 1 in C++");
790838fd1498Szrj       else
790938fd1498Szrj 	warning_at (record_loc, OPT_Wc___compat,
791038fd1498Szrj 		    "empty union has size 0 in C, size 1 in C++");
791138fd1498Szrj     }
791238fd1498Szrj 
791338fd1498Szrj   /* Set the C_TYPE_DEFINED_IN_STRUCT flag for each type defined in
791438fd1498Szrj      the current struct.  We do this now at the end of the struct
791538fd1498Szrj      because the flag is used to issue visibility warnings, and we
791638fd1498Szrj      only want to issue those warnings if the type is referenced
791738fd1498Szrj      outside of the struct declaration.  */
791838fd1498Szrj   FOR_EACH_VEC_ELT (struct_parse_info->struct_types, ix, x)
791938fd1498Szrj     C_TYPE_DEFINED_IN_STRUCT (x) = 1;
792038fd1498Szrj 
792138fd1498Szrj   /* The TYPEDEFS_SEEN field of STRUCT_PARSE_INFO is a list of
792238fd1498Szrj      typedefs used when declaring fields in this struct.  If the name
792338fd1498Szrj      of any of the fields is also a typedef name then the struct would
792438fd1498Szrj      not parse in C++, because the C++ lookup rules say that the
792538fd1498Szrj      typedef name would be looked up in the context of the struct, and
792638fd1498Szrj      would thus be the field rather than the typedef.  */
792738fd1498Szrj   if (!struct_parse_info->typedefs_seen.is_empty ()
792838fd1498Szrj       && fieldlist != NULL_TREE)
792938fd1498Szrj     {
793038fd1498Szrj       /* Use a hash_set<tree> using the name of the typedef.  We can use
793138fd1498Szrj 	 a hash_set<tree> because identifiers are interned.  */
793238fd1498Szrj       hash_set<tree> tset;
793338fd1498Szrj 
793438fd1498Szrj       FOR_EACH_VEC_ELT (struct_parse_info->typedefs_seen, ix, x)
793538fd1498Szrj 	tset.add (DECL_NAME (x));
793638fd1498Szrj 
793738fd1498Szrj       for (x = fieldlist; x != NULL_TREE; x = DECL_CHAIN (x))
793838fd1498Szrj 	{
793938fd1498Szrj 	  if (DECL_NAME (x) != NULL_TREE
794038fd1498Szrj 	      && tset.contains (DECL_NAME (x)))
794138fd1498Szrj 	    {
794238fd1498Szrj 	      warning_at (DECL_SOURCE_LOCATION (x), OPT_Wc___compat,
794338fd1498Szrj 			  ("using %qD as both field and typedef name is "
794438fd1498Szrj 			   "invalid in C++"),
794538fd1498Szrj 			  x);
794638fd1498Szrj 	      /* FIXME: It would be nice to report the location where
794738fd1498Szrj 		 the typedef name is used.  */
794838fd1498Szrj 	    }
794938fd1498Szrj 	}
795038fd1498Szrj     }
795138fd1498Szrj 
795238fd1498Szrj   /* For each field which has a binding and which was not defined in
795338fd1498Szrj      an enclosing struct, clear the in_struct field.  */
795438fd1498Szrj   FOR_EACH_VEC_ELT (struct_parse_info->fields, ix, b)
795538fd1498Szrj     b->in_struct = 0;
795638fd1498Szrj }
795738fd1498Szrj 
795838fd1498Szrj /* Function to help qsort sort FIELD_DECLs by name order.  */
795938fd1498Szrj 
796038fd1498Szrj static int
field_decl_cmp(const void * x_p,const void * y_p)796138fd1498Szrj field_decl_cmp (const void *x_p, const void *y_p)
796238fd1498Szrj {
796338fd1498Szrj   const tree *const x = (const tree *) x_p;
796438fd1498Szrj   const tree *const y = (const tree *) y_p;
796538fd1498Szrj 
796638fd1498Szrj   if (DECL_NAME (*x) == DECL_NAME (*y))
796738fd1498Szrj     /* A nontype is "greater" than a type.  */
796838fd1498Szrj     return (TREE_CODE (*y) == TYPE_DECL) - (TREE_CODE (*x) == TYPE_DECL);
796938fd1498Szrj   if (DECL_NAME (*x) == NULL_TREE)
797038fd1498Szrj     return -1;
797138fd1498Szrj   if (DECL_NAME (*y) == NULL_TREE)
797238fd1498Szrj     return 1;
797338fd1498Szrj   if (DECL_NAME (*x) < DECL_NAME (*y))
797438fd1498Szrj     return -1;
797538fd1498Szrj   return 1;
797638fd1498Szrj }
797738fd1498Szrj 
797838fd1498Szrj /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
797938fd1498Szrj    LOC is the location of the RECORD_TYPE or UNION_TYPE's definition.
798038fd1498Szrj    FIELDLIST is a chain of FIELD_DECL nodes for the fields.
798138fd1498Szrj    ATTRIBUTES are attributes to be applied to the structure.
798238fd1498Szrj 
798338fd1498Szrj    ENCLOSING_STRUCT_PARSE_INFO is the value of STRUCT_PARSE_INFO when
798438fd1498Szrj    the struct was started.  */
798538fd1498Szrj 
798638fd1498Szrj tree
finish_struct(location_t loc,tree t,tree fieldlist,tree attributes,struct c_struct_parse_info * enclosing_struct_parse_info)798738fd1498Szrj finish_struct (location_t loc, tree t, tree fieldlist, tree attributes,
798838fd1498Szrj 	       struct c_struct_parse_info *enclosing_struct_parse_info)
798938fd1498Szrj {
799038fd1498Szrj   tree x;
799138fd1498Szrj   bool toplevel = file_scope == current_scope;
799238fd1498Szrj 
799338fd1498Szrj   /* If this type was previously laid out as a forward reference,
799438fd1498Szrj      make sure we lay it out again.  */
799538fd1498Szrj 
799638fd1498Szrj   TYPE_SIZE (t) = NULL_TREE;
799738fd1498Szrj 
799838fd1498Szrj   decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
799938fd1498Szrj 
800038fd1498Szrj   if (pedantic)
800138fd1498Szrj     {
800238fd1498Szrj       for (x = fieldlist; x; x = DECL_CHAIN (x))
800338fd1498Szrj 	{
800438fd1498Szrj 	  if (DECL_NAME (x) != NULL_TREE)
800538fd1498Szrj 	    break;
800638fd1498Szrj 	  if (flag_isoc11 && RECORD_OR_UNION_TYPE_P (TREE_TYPE (x)))
800738fd1498Szrj 	    break;
800838fd1498Szrj 	}
800938fd1498Szrj 
801038fd1498Szrj       if (x == NULL_TREE)
801138fd1498Szrj 	{
801238fd1498Szrj 	  if (TREE_CODE (t) == UNION_TYPE)
801338fd1498Szrj 	    {
801438fd1498Szrj 	      if (fieldlist)
801538fd1498Szrj 		pedwarn (loc, OPT_Wpedantic, "union has no named members");
801638fd1498Szrj 	      else
801738fd1498Szrj 		pedwarn (loc, OPT_Wpedantic, "union has no members");
801838fd1498Szrj 	    }
801938fd1498Szrj 	  else
802038fd1498Szrj 	    {
802138fd1498Szrj 	      if (fieldlist)
802238fd1498Szrj 		pedwarn (loc, OPT_Wpedantic, "struct has no named members");
802338fd1498Szrj 	      else
802438fd1498Szrj 		pedwarn (loc, OPT_Wpedantic, "struct has no members");
802538fd1498Szrj 	    }
802638fd1498Szrj 	}
802738fd1498Szrj     }
802838fd1498Szrj 
802938fd1498Szrj   /* Install struct as DECL_CONTEXT of each field decl.
803038fd1498Szrj      Also process specified field sizes, found in the DECL_INITIAL,
803138fd1498Szrj      storing 0 there after the type has been changed to precision equal
803238fd1498Szrj      to its width, rather than the precision of the specified standard
803338fd1498Szrj      type.  (Correct layout requires the original type to have been preserved
803438fd1498Szrj      until now.)  */
803538fd1498Szrj 
803638fd1498Szrj   bool saw_named_field = false;
803738fd1498Szrj   for (x = fieldlist; x; x = DECL_CHAIN (x))
803838fd1498Szrj     {
803938fd1498Szrj       if (TREE_TYPE (x) == error_mark_node)
804038fd1498Szrj 	continue;
804138fd1498Szrj 
804238fd1498Szrj       DECL_CONTEXT (x) = t;
804338fd1498Szrj 
804438fd1498Szrj       /* If any field is const, the structure type is pseudo-const.  */
804538fd1498Szrj       if (TREE_READONLY (x))
804638fd1498Szrj 	C_TYPE_FIELDS_READONLY (t) = 1;
804738fd1498Szrj       else
804838fd1498Szrj 	{
804938fd1498Szrj 	  /* A field that is pseudo-const makes the structure likewise.  */
805038fd1498Szrj 	  tree t1 = strip_array_types (TREE_TYPE (x));
805138fd1498Szrj 	  if (RECORD_OR_UNION_TYPE_P (t1) && C_TYPE_FIELDS_READONLY (t1))
805238fd1498Szrj 	    C_TYPE_FIELDS_READONLY (t) = 1;
805338fd1498Szrj 	}
805438fd1498Szrj 
805538fd1498Szrj       /* Any field that is volatile means variables of this type must be
805638fd1498Szrj 	 treated in some ways as volatile.  */
805738fd1498Szrj       if (TREE_THIS_VOLATILE (x))
805838fd1498Szrj 	C_TYPE_FIELDS_VOLATILE (t) = 1;
805938fd1498Szrj 
806038fd1498Szrj       /* Any field of nominal variable size implies structure is too.  */
806138fd1498Szrj       if (C_DECL_VARIABLE_SIZE (x))
806238fd1498Szrj 	C_TYPE_VARIABLE_SIZE (t) = 1;
806338fd1498Szrj 
806438fd1498Szrj       if (DECL_C_BIT_FIELD (x))
806538fd1498Szrj 	{
806638fd1498Szrj 	  unsigned HOST_WIDE_INT width = tree_to_uhwi (DECL_INITIAL (x));
806738fd1498Szrj 	  DECL_SIZE (x) = bitsize_int (width);
806838fd1498Szrj 	  DECL_BIT_FIELD (x) = 1;
806938fd1498Szrj 	}
807038fd1498Szrj 
807138fd1498Szrj       if (TYPE_PACKED (t)
807238fd1498Szrj 	  && (DECL_BIT_FIELD (x)
807338fd1498Szrj 	      || TYPE_ALIGN (TREE_TYPE (x)) > BITS_PER_UNIT))
807438fd1498Szrj 	DECL_PACKED (x) = 1;
807538fd1498Szrj 
807638fd1498Szrj       /* Detect flexible array member in an invalid context.  */
807738fd1498Szrj       if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
807838fd1498Szrj 	  && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
807938fd1498Szrj 	  && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE
808038fd1498Szrj 	  && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE)
808138fd1498Szrj 	{
808238fd1498Szrj 	  if (TREE_CODE (t) == UNION_TYPE)
808338fd1498Szrj 	    {
808438fd1498Szrj 	      error_at (DECL_SOURCE_LOCATION (x),
808538fd1498Szrj 			"flexible array member in union");
808638fd1498Szrj 	      TREE_TYPE (x) = error_mark_node;
808738fd1498Szrj 	    }
808838fd1498Szrj 	  else if (DECL_CHAIN (x) != NULL_TREE)
808938fd1498Szrj 	    {
809038fd1498Szrj 	      error_at (DECL_SOURCE_LOCATION (x),
809138fd1498Szrj 			"flexible array member not at end of struct");
809238fd1498Szrj 	      TREE_TYPE (x) = error_mark_node;
809338fd1498Szrj 	    }
809438fd1498Szrj 	  else if (!saw_named_field)
809538fd1498Szrj 	    {
809638fd1498Szrj 	      error_at (DECL_SOURCE_LOCATION (x),
809738fd1498Szrj 			"flexible array member in a struct with no named "
809838fd1498Szrj 			"members");
809938fd1498Szrj 	      TREE_TYPE (x) = error_mark_node;
810038fd1498Szrj 	    }
810138fd1498Szrj 	}
810238fd1498Szrj 
810338fd1498Szrj       if (pedantic && TREE_CODE (t) == RECORD_TYPE
810438fd1498Szrj 	  && flexible_array_type_p (TREE_TYPE (x)))
810538fd1498Szrj 	pedwarn (DECL_SOURCE_LOCATION (x), OPT_Wpedantic,
810638fd1498Szrj 		 "invalid use of structure with flexible array member");
810738fd1498Szrj 
810838fd1498Szrj       if (DECL_NAME (x)
810938fd1498Szrj 	  || RECORD_OR_UNION_TYPE_P (TREE_TYPE (x)))
811038fd1498Szrj 	saw_named_field = true;
811138fd1498Szrj     }
811238fd1498Szrj 
811338fd1498Szrj   detect_field_duplicates (fieldlist);
811438fd1498Szrj 
811538fd1498Szrj   /* Now we have the nearly final fieldlist.  Record it,
811638fd1498Szrj      then lay out the structure or union (including the fields).  */
811738fd1498Szrj 
811838fd1498Szrj   TYPE_FIELDS (t) = fieldlist;
811938fd1498Szrj 
812038fd1498Szrj   maybe_apply_pragma_scalar_storage_order (t);
812138fd1498Szrj 
812238fd1498Szrj   layout_type (t);
812338fd1498Szrj 
812438fd1498Szrj   if (TYPE_SIZE_UNIT (t)
812538fd1498Szrj       && TREE_CODE (TYPE_SIZE_UNIT (t)) == INTEGER_CST
812638fd1498Szrj       && !TREE_OVERFLOW (TYPE_SIZE_UNIT (t))
812738fd1498Szrj       && !valid_constant_size_p (TYPE_SIZE_UNIT (t)))
812838fd1498Szrj     error ("type %qT is too large", t);
812938fd1498Szrj 
813038fd1498Szrj   /* Give bit-fields their proper types and rewrite the type of array fields
813138fd1498Szrj      with scalar component if the enclosing type has reverse storage order.  */
813238fd1498Szrj   for (tree field = fieldlist; field; field = DECL_CHAIN (field))
813338fd1498Szrj     {
813438fd1498Szrj       if (TREE_CODE (field) == FIELD_DECL
813538fd1498Szrj 	  && DECL_INITIAL (field)
813638fd1498Szrj 	  && TREE_TYPE (field) != error_mark_node)
813738fd1498Szrj 	{
813838fd1498Szrj 	  unsigned HOST_WIDE_INT width
813938fd1498Szrj 	    = tree_to_uhwi (DECL_INITIAL (field));
814038fd1498Szrj 	  tree type = TREE_TYPE (field);
814138fd1498Szrj 	  if (width != TYPE_PRECISION (type))
814238fd1498Szrj 	    {
814338fd1498Szrj 	      TREE_TYPE (field)
814438fd1498Szrj 		= c_build_bitfield_integer_type (width, TYPE_UNSIGNED (type));
814538fd1498Szrj 	      SET_DECL_MODE (field, TYPE_MODE (TREE_TYPE (field)));
814638fd1498Szrj 	    }
814738fd1498Szrj 	  DECL_INITIAL (field) = NULL_TREE;
814838fd1498Szrj 	}
814938fd1498Szrj       else if (TYPE_REVERSE_STORAGE_ORDER (t)
815038fd1498Szrj 	       && TREE_CODE (field) == FIELD_DECL
815138fd1498Szrj 	       && TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE)
815238fd1498Szrj 	{
815338fd1498Szrj 	  tree ftype = TREE_TYPE (field);
815438fd1498Szrj 	  tree ctype = strip_array_types (ftype);
815538fd1498Szrj 	  if (!RECORD_OR_UNION_TYPE_P (ctype) && TYPE_MODE (ctype) != QImode)
815638fd1498Szrj 	    {
815738fd1498Szrj 	      tree fmain_type = TYPE_MAIN_VARIANT (ftype);
815838fd1498Szrj 	      tree *typep = &fmain_type;
815938fd1498Szrj 	      do {
816038fd1498Szrj 		*typep = build_distinct_type_copy (*typep);
816138fd1498Szrj 		TYPE_REVERSE_STORAGE_ORDER (*typep) = 1;
816238fd1498Szrj 		typep = &TREE_TYPE (*typep);
816338fd1498Szrj 	      } while (TREE_CODE (*typep) == ARRAY_TYPE);
816438fd1498Szrj 	      TREE_TYPE (field)
816538fd1498Szrj 		= c_build_qualified_type (fmain_type, TYPE_QUALS (ftype));
816638fd1498Szrj 	    }
816738fd1498Szrj 	}
816838fd1498Szrj     }
816938fd1498Szrj 
817038fd1498Szrj   /* Now we have the truly final field list.
817138fd1498Szrj      Store it in this type and in the variants.  */
817238fd1498Szrj 
817338fd1498Szrj   TYPE_FIELDS (t) = fieldlist;
817438fd1498Szrj 
817538fd1498Szrj   /* If there are lots of fields, sort so we can look through them fast.
817638fd1498Szrj      We arbitrarily consider 16 or more elts to be "a lot".  */
817738fd1498Szrj 
817838fd1498Szrj   {
817938fd1498Szrj     int len = 0;
818038fd1498Szrj 
818138fd1498Szrj     for (x = fieldlist; x; x = DECL_CHAIN (x))
818238fd1498Szrj       {
818338fd1498Szrj 	if (len > 15 || DECL_NAME (x) == NULL)
818438fd1498Szrj 	  break;
818538fd1498Szrj 	len += 1;
818638fd1498Szrj       }
818738fd1498Szrj 
818838fd1498Szrj     if (len > 15)
818938fd1498Szrj       {
819038fd1498Szrj 	tree *field_array;
819138fd1498Szrj 	struct lang_type *space;
819238fd1498Szrj 	struct sorted_fields_type *space2;
819338fd1498Szrj 
819438fd1498Szrj 	len += list_length (x);
819538fd1498Szrj 
819638fd1498Szrj 	/* Use the same allocation policy here that make_node uses, to
819738fd1498Szrj 	  ensure that this lives as long as the rest of the struct decl.
819838fd1498Szrj 	  All decls in an inline function need to be saved.  */
819938fd1498Szrj 
820038fd1498Szrj 	space = ggc_cleared_alloc<struct lang_type> ();
820138fd1498Szrj 	space2 = (sorted_fields_type *) ggc_internal_alloc
820238fd1498Szrj 	  (sizeof (struct sorted_fields_type) + len * sizeof (tree));
820338fd1498Szrj 
820438fd1498Szrj 	len = 0;
820538fd1498Szrj 	space->s = space2;
820638fd1498Szrj 	field_array = &space2->elts[0];
820738fd1498Szrj 	for (x = fieldlist; x; x = DECL_CHAIN (x))
820838fd1498Szrj 	  {
820938fd1498Szrj 	    field_array[len++] = x;
821038fd1498Szrj 
821138fd1498Szrj 	    /* If there is anonymous struct or union, break out of the loop.  */
821238fd1498Szrj 	    if (DECL_NAME (x) == NULL)
821338fd1498Szrj 	      break;
821438fd1498Szrj 	  }
821538fd1498Szrj 	/* Found no anonymous struct/union.  Add the TYPE_LANG_SPECIFIC.  */
821638fd1498Szrj 	if (x == NULL)
821738fd1498Szrj 	  {
821838fd1498Szrj 	    TYPE_LANG_SPECIFIC (t) = space;
821938fd1498Szrj 	    TYPE_LANG_SPECIFIC (t)->s->len = len;
822038fd1498Szrj 	    field_array = TYPE_LANG_SPECIFIC (t)->s->elts;
822138fd1498Szrj 	    qsort (field_array, len, sizeof (tree), field_decl_cmp);
822238fd1498Szrj 	  }
822338fd1498Szrj       }
822438fd1498Szrj   }
822538fd1498Szrj 
822638fd1498Szrj   /* Note: C_TYPE_INCOMPLETE_VARS overloads TYPE_VFIELD which is used
822738fd1498Szrj      in dwarf2out via rest_of_decl_compilation below and means
822838fd1498Szrj      something totally different.  Since we will be clearing
822938fd1498Szrj      C_TYPE_INCOMPLETE_VARS shortly after we iterate through them,
823038fd1498Szrj      clear it ahead of time and avoid problems in dwarf2out.  Ideally,
823138fd1498Szrj      C_TYPE_INCOMPLETE_VARS should use some language specific
823238fd1498Szrj      node.  */
823338fd1498Szrj   tree incomplete_vars = C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t));
823438fd1498Szrj   for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
823538fd1498Szrj     {
823638fd1498Szrj       TYPE_FIELDS (x) = TYPE_FIELDS (t);
823738fd1498Szrj       TYPE_LANG_SPECIFIC (x) = TYPE_LANG_SPECIFIC (t);
823838fd1498Szrj       C_TYPE_FIELDS_READONLY (x) = C_TYPE_FIELDS_READONLY (t);
823938fd1498Szrj       C_TYPE_FIELDS_VOLATILE (x) = C_TYPE_FIELDS_VOLATILE (t);
824038fd1498Szrj       C_TYPE_VARIABLE_SIZE (x) = C_TYPE_VARIABLE_SIZE (t);
824138fd1498Szrj       C_TYPE_INCOMPLETE_VARS (x) = NULL_TREE;
824238fd1498Szrj     }
824338fd1498Szrj 
824438fd1498Szrj   /* If this was supposed to be a transparent union, but we can't
824538fd1498Szrj      make it one, warn and turn off the flag.  */
824638fd1498Szrj   if (TREE_CODE (t) == UNION_TYPE
824738fd1498Szrj       && TYPE_TRANSPARENT_AGGR (t)
824838fd1498Szrj       && (!TYPE_FIELDS (t) || TYPE_MODE (t) != DECL_MODE (TYPE_FIELDS (t))))
824938fd1498Szrj     {
825038fd1498Szrj       TYPE_TRANSPARENT_AGGR (t) = 0;
825138fd1498Szrj       warning_at (loc, 0, "union cannot be made transparent");
825238fd1498Szrj     }
825338fd1498Szrj 
825438fd1498Szrj   /* Update type location to the one of the definition, instead of e.g.
825538fd1498Szrj      a forward declaration.  */
825638fd1498Szrj   if (TYPE_STUB_DECL (t))
825738fd1498Szrj     DECL_SOURCE_LOCATION (TYPE_STUB_DECL (t)) = loc;
825838fd1498Szrj 
825938fd1498Szrj   /* Finish debugging output for this type.  */
826038fd1498Szrj   rest_of_type_compilation (t, toplevel);
826138fd1498Szrj 
826238fd1498Szrj   /* If this structure or union completes the type of any previous
826338fd1498Szrj      variable declaration, lay it out and output its rtl.  */
826438fd1498Szrj   for (x = incomplete_vars; x; x = TREE_CHAIN (x))
826538fd1498Szrj     {
826638fd1498Szrj       tree decl = TREE_VALUE (x);
826738fd1498Szrj       if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
826838fd1498Szrj 	layout_array_type (TREE_TYPE (decl));
826938fd1498Szrj       if (TREE_CODE (decl) != TYPE_DECL)
827038fd1498Szrj 	{
827138fd1498Szrj 	  layout_decl (decl, 0);
827238fd1498Szrj 	  if (c_dialect_objc ())
827338fd1498Szrj 	    objc_check_decl (decl);
827438fd1498Szrj 	  rest_of_decl_compilation (decl, toplevel, 0);
827538fd1498Szrj 	}
827638fd1498Szrj     }
827738fd1498Szrj 
827838fd1498Szrj   /* If we're inside a function proper, i.e. not file-scope and not still
827938fd1498Szrj      parsing parameters, then arrange for the size of a variable sized type
828038fd1498Szrj      to be bound now.  */
828138fd1498Szrj   if (building_stmt_list_p () && variably_modified_type_p (t, NULL_TREE))
828238fd1498Szrj     add_stmt (build_stmt (loc,
828338fd1498Szrj 			  DECL_EXPR, build_decl (loc, TYPE_DECL, NULL, t)));
828438fd1498Szrj 
828538fd1498Szrj   if (warn_cxx_compat)
828638fd1498Szrj     warn_cxx_compat_finish_struct (fieldlist, TREE_CODE (t), loc);
828738fd1498Szrj 
828838fd1498Szrj   delete struct_parse_info;
828938fd1498Szrj 
829038fd1498Szrj   struct_parse_info = enclosing_struct_parse_info;
829138fd1498Szrj 
829238fd1498Szrj   /* If this struct is defined inside a struct, add it to
829338fd1498Szrj      struct_types.  */
829438fd1498Szrj   if (warn_cxx_compat
829538fd1498Szrj       && struct_parse_info != NULL
829638fd1498Szrj       && !in_sizeof && !in_typeof && !in_alignof)
829738fd1498Szrj     struct_parse_info->struct_types.safe_push (t);
829838fd1498Szrj 
829938fd1498Szrj   return t;
830038fd1498Szrj }
830138fd1498Szrj 
830238fd1498Szrj static struct {
830338fd1498Szrj   gt_pointer_operator new_value;
830438fd1498Szrj   void *cookie;
830538fd1498Szrj } resort_data;
830638fd1498Szrj 
830738fd1498Szrj /* This routine compares two fields like field_decl_cmp but using the
830838fd1498Szrj pointer operator in resort_data.  */
830938fd1498Szrj 
831038fd1498Szrj static int
resort_field_decl_cmp(const void * x_p,const void * y_p)831138fd1498Szrj resort_field_decl_cmp (const void *x_p, const void *y_p)
831238fd1498Szrj {
831338fd1498Szrj   const tree *const x = (const tree *) x_p;
831438fd1498Szrj   const tree *const y = (const tree *) y_p;
831538fd1498Szrj 
831638fd1498Szrj   if (DECL_NAME (*x) == DECL_NAME (*y))
831738fd1498Szrj     /* A nontype is "greater" than a type.  */
831838fd1498Szrj     return (TREE_CODE (*y) == TYPE_DECL) - (TREE_CODE (*x) == TYPE_DECL);
831938fd1498Szrj   if (DECL_NAME (*x) == NULL_TREE)
832038fd1498Szrj     return -1;
832138fd1498Szrj   if (DECL_NAME (*y) == NULL_TREE)
832238fd1498Szrj     return 1;
832338fd1498Szrj   {
832438fd1498Szrj     tree d1 = DECL_NAME (*x);
832538fd1498Szrj     tree d2 = DECL_NAME (*y);
832638fd1498Szrj     resort_data.new_value (&d1, resort_data.cookie);
832738fd1498Szrj     resort_data.new_value (&d2, resort_data.cookie);
832838fd1498Szrj     if (d1 < d2)
832938fd1498Szrj       return -1;
833038fd1498Szrj   }
833138fd1498Szrj   return 1;
833238fd1498Szrj }
833338fd1498Szrj 
833438fd1498Szrj /* Resort DECL_SORTED_FIELDS because pointers have been reordered.  */
833538fd1498Szrj 
833638fd1498Szrj void
resort_sorted_fields(void * obj,void * ARG_UNUSED (orig_obj),gt_pointer_operator new_value,void * cookie)833738fd1498Szrj resort_sorted_fields (void *obj,
833838fd1498Szrj 		      void * ARG_UNUSED (orig_obj),
833938fd1498Szrj 		      gt_pointer_operator new_value,
834038fd1498Szrj 		      void *cookie)
834138fd1498Szrj {
834238fd1498Szrj   struct sorted_fields_type *sf = (struct sorted_fields_type *) obj;
834338fd1498Szrj   resort_data.new_value = new_value;
834438fd1498Szrj   resort_data.cookie = cookie;
834538fd1498Szrj   qsort (&sf->elts[0], sf->len, sizeof (tree),
834638fd1498Szrj 	 resort_field_decl_cmp);
834738fd1498Szrj }
834838fd1498Szrj 
834938fd1498Szrj /* Lay out the type T, and its element type, and so on.  */
835038fd1498Szrj 
835138fd1498Szrj static void
layout_array_type(tree t)835238fd1498Szrj layout_array_type (tree t)
835338fd1498Szrj {
835438fd1498Szrj   if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
835538fd1498Szrj     layout_array_type (TREE_TYPE (t));
835638fd1498Szrj   layout_type (t);
835738fd1498Szrj }
835838fd1498Szrj 
835938fd1498Szrj /* Begin compiling the definition of an enumeration type.
836038fd1498Szrj    NAME is its name (or null if anonymous).
836138fd1498Szrj    LOC is the enum's location.
836238fd1498Szrj    Returns the type object, as yet incomplete.
836338fd1498Szrj    Also records info about it so that build_enumerator
836438fd1498Szrj    may be used to declare the individual values as they are read.  */
836538fd1498Szrj 
836638fd1498Szrj tree
start_enum(location_t loc,struct c_enum_contents * the_enum,tree name)836738fd1498Szrj start_enum (location_t loc, struct c_enum_contents *the_enum, tree name)
836838fd1498Szrj {
836938fd1498Szrj   tree enumtype = NULL_TREE;
837038fd1498Szrj   location_t enumloc = UNKNOWN_LOCATION;
837138fd1498Szrj 
837238fd1498Szrj   /* If this is the real definition for a previous forward reference,
837338fd1498Szrj      fill in the contents in the same object that used to be the
837438fd1498Szrj      forward reference.  */
837538fd1498Szrj 
837638fd1498Szrj   if (name != NULL_TREE)
837738fd1498Szrj     enumtype = lookup_tag (ENUMERAL_TYPE, name, true, &enumloc);
837838fd1498Szrj 
837938fd1498Szrj   if (enumtype == NULL_TREE || TREE_CODE (enumtype) != ENUMERAL_TYPE)
838038fd1498Szrj     {
838138fd1498Szrj       enumtype = make_node (ENUMERAL_TYPE);
838238fd1498Szrj       pushtag (loc, name, enumtype);
838338fd1498Szrj     }
838438fd1498Szrj   /* Update type location to the one of the definition, instead of e.g.
838538fd1498Szrj      a forward declaration.  */
838638fd1498Szrj   else if (TYPE_STUB_DECL (enumtype))
838738fd1498Szrj     {
838838fd1498Szrj       enumloc = DECL_SOURCE_LOCATION (TYPE_STUB_DECL (enumtype));
838938fd1498Szrj       DECL_SOURCE_LOCATION (TYPE_STUB_DECL (enumtype)) = loc;
839038fd1498Szrj     }
839138fd1498Szrj 
839238fd1498Szrj   if (C_TYPE_BEING_DEFINED (enumtype))
839338fd1498Szrj     error_at (loc, "nested redefinition of %<enum %E%>", name);
839438fd1498Szrj 
839538fd1498Szrj   C_TYPE_BEING_DEFINED (enumtype) = 1;
839638fd1498Szrj 
839738fd1498Szrj   if (TYPE_VALUES (enumtype) != NULL_TREE)
839838fd1498Szrj     {
839938fd1498Szrj       /* This enum is a named one that has been declared already.  */
840038fd1498Szrj       error_at (loc, "redeclaration of %<enum %E%>", name);
840138fd1498Szrj       if (enumloc != UNKNOWN_LOCATION)
840238fd1498Szrj 	inform (enumloc, "originally defined here");
840338fd1498Szrj 
840438fd1498Szrj       /* Completely replace its old definition.
840538fd1498Szrj 	 The old enumerators remain defined, however.  */
840638fd1498Szrj       TYPE_VALUES (enumtype) = NULL_TREE;
840738fd1498Szrj     }
840838fd1498Szrj 
840938fd1498Szrj   the_enum->enum_next_value = integer_zero_node;
841038fd1498Szrj   the_enum->enum_overflow = 0;
841138fd1498Szrj 
841238fd1498Szrj   if (flag_short_enums)
841338fd1498Szrj     for (tree v = TYPE_MAIN_VARIANT (enumtype); v; v = TYPE_NEXT_VARIANT (v))
841438fd1498Szrj       TYPE_PACKED (v) = 1;
841538fd1498Szrj 
841638fd1498Szrj   /* FIXME: This will issue a warning for a use of a type defined
841738fd1498Szrj      within sizeof in a statement expr.  This is not terribly serious
841838fd1498Szrj      as C++ doesn't permit statement exprs within sizeof anyhow.  */
841938fd1498Szrj   if (warn_cxx_compat && (in_sizeof || in_typeof || in_alignof))
842038fd1498Szrj     warning_at (loc, OPT_Wc___compat,
842138fd1498Szrj 		"defining type in %qs expression is invalid in C++",
842238fd1498Szrj 		(in_sizeof
842338fd1498Szrj 		 ? "sizeof"
842438fd1498Szrj 		 : (in_typeof ? "typeof" : "alignof")));
842538fd1498Szrj 
842638fd1498Szrj   return enumtype;
842738fd1498Szrj }
842838fd1498Szrj 
842938fd1498Szrj /* After processing and defining all the values of an enumeration type,
843038fd1498Szrj    install their decls in the enumeration type and finish it off.
843138fd1498Szrj    ENUMTYPE is the type object, VALUES a list of decl-value pairs,
843238fd1498Szrj    and ATTRIBUTES are the specified attributes.
843338fd1498Szrj    Returns ENUMTYPE.  */
843438fd1498Szrj 
843538fd1498Szrj tree
finish_enum(tree enumtype,tree values,tree attributes)843638fd1498Szrj finish_enum (tree enumtype, tree values, tree attributes)
843738fd1498Szrj {
843838fd1498Szrj   tree pair, tem;
843938fd1498Szrj   tree minnode = NULL_TREE, maxnode = NULL_TREE;
844038fd1498Szrj   int precision;
844138fd1498Szrj   signop sign;
844238fd1498Szrj   bool toplevel = (file_scope == current_scope);
844338fd1498Szrj   struct lang_type *lt;
844438fd1498Szrj 
844538fd1498Szrj   decl_attributes (&enumtype, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
844638fd1498Szrj 
844738fd1498Szrj   /* Calculate the maximum value of any enumerator in this type.  */
844838fd1498Szrj 
844938fd1498Szrj   if (values == error_mark_node)
845038fd1498Szrj     minnode = maxnode = integer_zero_node;
845138fd1498Szrj   else
845238fd1498Szrj     {
845338fd1498Szrj       minnode = maxnode = TREE_VALUE (values);
845438fd1498Szrj       for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
845538fd1498Szrj 	{
845638fd1498Szrj 	  tree value = TREE_VALUE (pair);
845738fd1498Szrj 	  if (tree_int_cst_lt (maxnode, value))
845838fd1498Szrj 	    maxnode = value;
845938fd1498Szrj 	  if (tree_int_cst_lt (value, minnode))
846038fd1498Szrj 	    minnode = value;
846138fd1498Szrj 	}
846238fd1498Szrj     }
846338fd1498Szrj 
846438fd1498Szrj   /* Construct the final type of this enumeration.  It is the same
846538fd1498Szrj      as one of the integral types - the narrowest one that fits, except
846638fd1498Szrj      that normally we only go as narrow as int - and signed iff any of
846738fd1498Szrj      the values are negative.  */
846838fd1498Szrj   sign = (tree_int_cst_sgn (minnode) >= 0) ? UNSIGNED : SIGNED;
846938fd1498Szrj   precision = MAX (tree_int_cst_min_precision (minnode, sign),
847038fd1498Szrj 		   tree_int_cst_min_precision (maxnode, sign));
847138fd1498Szrj 
847238fd1498Szrj   /* If the precision of the type was specified with an attribute and it
847338fd1498Szrj      was too small, give an error.  Otherwise, use it.  */
847438fd1498Szrj   if (TYPE_PRECISION (enumtype) && lookup_attribute ("mode", attributes))
847538fd1498Szrj     {
847638fd1498Szrj       if (precision > TYPE_PRECISION (enumtype))
847738fd1498Szrj 	{
847838fd1498Szrj 	  TYPE_PRECISION (enumtype) = 0;
847938fd1498Szrj 	  error ("specified mode too small for enumeral values");
848038fd1498Szrj 	}
848138fd1498Szrj       else
848238fd1498Szrj 	precision = TYPE_PRECISION (enumtype);
848338fd1498Szrj     }
848438fd1498Szrj   else
848538fd1498Szrj     TYPE_PRECISION (enumtype) = 0;
848638fd1498Szrj 
848738fd1498Szrj   if (TYPE_PACKED (enumtype)
848838fd1498Szrj       || precision > TYPE_PRECISION (integer_type_node)
848938fd1498Szrj       || TYPE_PRECISION (enumtype))
849038fd1498Szrj     {
849138fd1498Szrj       tem = c_common_type_for_size (precision, sign == UNSIGNED ? 1 : 0);
849238fd1498Szrj       if (tem == NULL)
849338fd1498Szrj 	{
849438fd1498Szrj 	  warning (0, "enumeration values exceed range of largest integer");
849538fd1498Szrj 	  tem = long_long_integer_type_node;
849638fd1498Szrj 	}
849738fd1498Szrj     }
849838fd1498Szrj   else
849938fd1498Szrj     tem = sign == UNSIGNED ? unsigned_type_node : integer_type_node;
850038fd1498Szrj 
850138fd1498Szrj   TYPE_MIN_VALUE (enumtype) = TYPE_MIN_VALUE (tem);
850238fd1498Szrj   TYPE_MAX_VALUE (enumtype) = TYPE_MAX_VALUE (tem);
850338fd1498Szrj   TYPE_UNSIGNED (enumtype) = TYPE_UNSIGNED (tem);
850438fd1498Szrj   SET_TYPE_ALIGN (enumtype, TYPE_ALIGN (tem));
850538fd1498Szrj   TYPE_SIZE (enumtype) = NULL_TREE;
850638fd1498Szrj   TYPE_PRECISION (enumtype) = TYPE_PRECISION (tem);
850738fd1498Szrj 
850838fd1498Szrj   layout_type (enumtype);
850938fd1498Szrj 
851038fd1498Szrj   if (values != error_mark_node)
851138fd1498Szrj     {
851238fd1498Szrj       /* Change the type of the enumerators to be the enum type.  We
851338fd1498Szrj 	 need to do this irrespective of the size of the enum, for
851438fd1498Szrj 	 proper type checking.  Replace the DECL_INITIALs of the
851538fd1498Szrj 	 enumerators, and the value slots of the list, with copies
851638fd1498Szrj 	 that have the enum type; they cannot be modified in place
851738fd1498Szrj 	 because they may be shared (e.g.  integer_zero_node) Finally,
851838fd1498Szrj 	 change the purpose slots to point to the names of the decls.  */
851938fd1498Szrj       for (pair = values; pair; pair = TREE_CHAIN (pair))
852038fd1498Szrj 	{
852138fd1498Szrj 	  tree enu = TREE_PURPOSE (pair);
852238fd1498Szrj 	  tree ini = DECL_INITIAL (enu);
852338fd1498Szrj 
852438fd1498Szrj 	  TREE_TYPE (enu) = enumtype;
852538fd1498Szrj 
852638fd1498Szrj 	  /* The ISO C Standard mandates enumerators to have type int,
852738fd1498Szrj 	     even though the underlying type of an enum type is
852838fd1498Szrj 	     unspecified.  However, GCC allows enumerators of any
852938fd1498Szrj 	     integer type as an extensions.  build_enumerator()
853038fd1498Szrj 	     converts any enumerators that fit in an int to type int,
853138fd1498Szrj 	     to avoid promotions to unsigned types when comparing
853238fd1498Szrj 	     integers with enumerators that fit in the int range.
853338fd1498Szrj 	     When -pedantic is given, build_enumerator() would have
853438fd1498Szrj 	     already warned about those that don't fit. Here we
853538fd1498Szrj 	     convert the rest to the enumerator type. */
853638fd1498Szrj 	  if (TREE_TYPE (ini) != integer_type_node)
853738fd1498Szrj 	    ini = convert (enumtype, ini);
853838fd1498Szrj 
853938fd1498Szrj 	  DECL_INITIAL (enu) = ini;
854038fd1498Szrj 	  TREE_PURPOSE (pair) = DECL_NAME (enu);
854138fd1498Szrj 	  TREE_VALUE (pair) = ini;
854238fd1498Szrj 	}
854338fd1498Szrj 
854438fd1498Szrj       TYPE_VALUES (enumtype) = values;
854538fd1498Szrj     }
854638fd1498Szrj 
854738fd1498Szrj   /* Record the min/max values so that we can warn about bit-field
854838fd1498Szrj      enumerations that are too small for the values.  */
854938fd1498Szrj   lt = ggc_cleared_alloc<struct lang_type> ();
855038fd1498Szrj   lt->enum_min = minnode;
855138fd1498Szrj   lt->enum_max = maxnode;
855238fd1498Szrj   TYPE_LANG_SPECIFIC (enumtype) = lt;
855338fd1498Szrj 
855438fd1498Szrj   /* Fix up all variant types of this enum type.  */
855538fd1498Szrj   for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem))
855638fd1498Szrj     {
855738fd1498Szrj       if (tem == enumtype)
855838fd1498Szrj 	continue;
855938fd1498Szrj       TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
856038fd1498Szrj       TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
856138fd1498Szrj       TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
856238fd1498Szrj       TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
856338fd1498Szrj       TYPE_SIZE_UNIT (tem) = TYPE_SIZE_UNIT (enumtype);
856438fd1498Szrj       SET_TYPE_MODE (tem, TYPE_MODE (enumtype));
856538fd1498Szrj       TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
856638fd1498Szrj       SET_TYPE_ALIGN (tem, TYPE_ALIGN (enumtype));
856738fd1498Szrj       TYPE_USER_ALIGN (tem) = TYPE_USER_ALIGN (enumtype);
856838fd1498Szrj       TYPE_UNSIGNED (tem) = TYPE_UNSIGNED (enumtype);
856938fd1498Szrj       TYPE_LANG_SPECIFIC (tem) = TYPE_LANG_SPECIFIC (enumtype);
857038fd1498Szrj     }
857138fd1498Szrj 
857238fd1498Szrj   /* Finish debugging output for this type.  */
857338fd1498Szrj   rest_of_type_compilation (enumtype, toplevel);
857438fd1498Szrj 
857538fd1498Szrj   /* If this enum is defined inside a struct, add it to
857638fd1498Szrj      struct_types.  */
857738fd1498Szrj   if (warn_cxx_compat
857838fd1498Szrj       && struct_parse_info != NULL
857938fd1498Szrj       && !in_sizeof && !in_typeof && !in_alignof)
858038fd1498Szrj     struct_parse_info->struct_types.safe_push (enumtype);
858138fd1498Szrj 
858238fd1498Szrj   return enumtype;
858338fd1498Szrj }
858438fd1498Szrj 
858538fd1498Szrj /* Build and install a CONST_DECL for one value of the
858638fd1498Szrj    current enumeration type (one that was begun with start_enum).
858738fd1498Szrj    DECL_LOC is the location of the enumerator.
858838fd1498Szrj    LOC is the location of the '=' operator if any, DECL_LOC otherwise.
858938fd1498Szrj    Return a tree-list containing the CONST_DECL and its value.
859038fd1498Szrj    Assignment of sequential values by default is handled here.  */
859138fd1498Szrj 
859238fd1498Szrj tree
build_enumerator(location_t decl_loc,location_t loc,struct c_enum_contents * the_enum,tree name,tree value)859338fd1498Szrj build_enumerator (location_t decl_loc, location_t loc,
859438fd1498Szrj 		  struct c_enum_contents *the_enum, tree name, tree value)
859538fd1498Szrj {
859638fd1498Szrj   tree decl, type;
859738fd1498Szrj 
859838fd1498Szrj   /* Validate and default VALUE.  */
859938fd1498Szrj 
860038fd1498Szrj   if (value != NULL_TREE)
860138fd1498Szrj     {
860238fd1498Szrj       /* Don't issue more errors for error_mark_node (i.e. an
860338fd1498Szrj 	 undeclared identifier) - just ignore the value expression.  */
860438fd1498Szrj       if (value == error_mark_node)
860538fd1498Szrj 	value = NULL_TREE;
860638fd1498Szrj       else if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
860738fd1498Szrj 	{
860838fd1498Szrj 	  error_at (loc, "enumerator value for %qE is not an integer constant",
860938fd1498Szrj 		    name);
861038fd1498Szrj 	  value = NULL_TREE;
861138fd1498Szrj 	}
861238fd1498Szrj       else
861338fd1498Szrj 	{
861438fd1498Szrj 	  if (TREE_CODE (value) != INTEGER_CST)
861538fd1498Szrj 	    {
861638fd1498Szrj 	      value = c_fully_fold (value, false, NULL);
861738fd1498Szrj 	      if (TREE_CODE (value) == INTEGER_CST)
861838fd1498Szrj 		pedwarn (loc, OPT_Wpedantic,
861938fd1498Szrj 			 "enumerator value for %qE is not an integer "
862038fd1498Szrj 			 "constant expression", name);
862138fd1498Szrj 	    }
862238fd1498Szrj 	  if (TREE_CODE (value) != INTEGER_CST)
862338fd1498Szrj 	    {
862438fd1498Szrj 	      error ("enumerator value for %qE is not an integer constant",
862538fd1498Szrj 		     name);
862638fd1498Szrj 	      value = NULL_TREE;
862738fd1498Szrj 	    }
862838fd1498Szrj 	  else
862938fd1498Szrj 	    {
863038fd1498Szrj 	      value = default_conversion (value);
863138fd1498Szrj 	      constant_expression_warning (value);
863238fd1498Szrj 	    }
863338fd1498Szrj 	}
863438fd1498Szrj     }
863538fd1498Szrj 
863638fd1498Szrj   /* Default based on previous value.  */
863738fd1498Szrj   /* It should no longer be possible to have NON_LVALUE_EXPR
863838fd1498Szrj      in the default.  */
863938fd1498Szrj   if (value == NULL_TREE)
864038fd1498Szrj     {
864138fd1498Szrj       value = the_enum->enum_next_value;
864238fd1498Szrj       if (the_enum->enum_overflow)
864338fd1498Szrj 	error_at (loc, "overflow in enumeration values");
864438fd1498Szrj     }
864538fd1498Szrj   /* Even though the underlying type of an enum is unspecified, the
864638fd1498Szrj      type of enumeration constants is explicitly defined as int
864738fd1498Szrj      (6.4.4.3/2 in the C99 Standard).  GCC allows any integer type as
864838fd1498Szrj      an extension.  */
864938fd1498Szrj   else if (!int_fits_type_p (value, integer_type_node))
865038fd1498Szrj     pedwarn (loc, OPT_Wpedantic,
865138fd1498Szrj 	     "ISO C restricts enumerator values to range of %<int%>");
865238fd1498Szrj 
865338fd1498Szrj   /* The ISO C Standard mandates enumerators to have type int, even
865438fd1498Szrj      though the underlying type of an enum type is unspecified.
865538fd1498Szrj      However, GCC allows enumerators of any integer type as an
865638fd1498Szrj      extensions.  Here we convert any enumerators that fit in an int
865738fd1498Szrj      to type int, to avoid promotions to unsigned types when comparing
865838fd1498Szrj      integers with enumerators that fit in the int range.  When
865938fd1498Szrj      -pedantic is given, we would have already warned about those that
866038fd1498Szrj      don't fit. We have to do this here rather than in finish_enum
866138fd1498Szrj      because this value may be used to define more enumerators.  */
866238fd1498Szrj   if (int_fits_type_p (value, integer_type_node))
866338fd1498Szrj     value = convert (integer_type_node, value);
866438fd1498Szrj 
866538fd1498Szrj   /* Set basis for default for next value.  */
866638fd1498Szrj   the_enum->enum_next_value
866738fd1498Szrj     = build_binary_op (EXPR_LOC_OR_LOC (value, input_location),
866838fd1498Szrj 		       PLUS_EXPR, value, integer_one_node, false);
866938fd1498Szrj   the_enum->enum_overflow = tree_int_cst_lt (the_enum->enum_next_value, value);
867038fd1498Szrj 
867138fd1498Szrj   /* Now create a declaration for the enum value name.  */
867238fd1498Szrj 
867338fd1498Szrj   type = TREE_TYPE (value);
867438fd1498Szrj   type = c_common_type_for_size (MAX (TYPE_PRECISION (type),
867538fd1498Szrj 				      TYPE_PRECISION (integer_type_node)),
867638fd1498Szrj 				 (TYPE_PRECISION (type)
867738fd1498Szrj 				  >= TYPE_PRECISION (integer_type_node)
867838fd1498Szrj 				  && TYPE_UNSIGNED (type)));
867938fd1498Szrj 
868038fd1498Szrj   decl = build_decl (decl_loc, CONST_DECL, name, type);
868138fd1498Szrj   DECL_INITIAL (decl) = convert (type, value);
868238fd1498Szrj   pushdecl (decl);
868338fd1498Szrj 
868438fd1498Szrj   return tree_cons (decl, value, NULL_TREE);
868538fd1498Szrj }
868638fd1498Szrj 
868738fd1498Szrj 
868838fd1498Szrj /* Create the FUNCTION_DECL for a function definition.
868938fd1498Szrj    DECLSPECS, DECLARATOR and ATTRIBUTES are the parts of
869038fd1498Szrj    the declaration; they describe the function's name and the type it returns,
869138fd1498Szrj    but twisted together in a fashion that parallels the syntax of C.
869238fd1498Szrj 
869338fd1498Szrj    This function creates a binding context for the function body
869438fd1498Szrj    as well as setting up the FUNCTION_DECL in current_function_decl.
869538fd1498Szrj 
869638fd1498Szrj    Returns true on success.  If the DECLARATOR is not suitable for a function
869738fd1498Szrj    (it defines a datum instead), we return false to report a parse error.  */
869838fd1498Szrj 
869938fd1498Szrj bool
start_function(struct c_declspecs * declspecs,struct c_declarator * declarator,tree attributes)870038fd1498Szrj start_function (struct c_declspecs *declspecs, struct c_declarator *declarator,
870138fd1498Szrj 		tree attributes)
870238fd1498Szrj {
870338fd1498Szrj   tree decl1, old_decl;
870438fd1498Szrj   tree restype, resdecl;
870538fd1498Szrj   location_t loc;
870638fd1498Szrj 
870738fd1498Szrj   current_function_returns_value = 0;  /* Assume, until we see it does.  */
870838fd1498Szrj   current_function_returns_null = 0;
870938fd1498Szrj   current_function_returns_abnormally = 0;
871038fd1498Szrj   warn_about_return_type = 0;
871138fd1498Szrj   c_switch_stack = NULL;
871238fd1498Szrj 
871338fd1498Szrj   /* Indicate no valid break/continue context by setting these variables
871438fd1498Szrj      to some non-null, non-label value.  We'll notice and emit the proper
871538fd1498Szrj      error message in c_finish_bc_stmt.  */
871638fd1498Szrj   c_break_label = c_cont_label = size_zero_node;
871738fd1498Szrj 
871838fd1498Szrj   decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, true, NULL,
871938fd1498Szrj 			  &attributes, NULL, NULL, DEPRECATED_NORMAL);
872038fd1498Szrj   invoke_plugin_callbacks (PLUGIN_START_PARSE_FUNCTION, decl1);
872138fd1498Szrj 
872238fd1498Szrj   /* If the declarator is not suitable for a function definition,
872338fd1498Szrj      cause a syntax error.  */
872438fd1498Szrj   if (decl1 == NULL_TREE
872538fd1498Szrj       || TREE_CODE (decl1) != FUNCTION_DECL)
872638fd1498Szrj     return false;
872738fd1498Szrj 
872838fd1498Szrj   loc = DECL_SOURCE_LOCATION (decl1);
872938fd1498Szrj 
873038fd1498Szrj   c_decl_attributes (&decl1, attributes, 0);
873138fd1498Szrj 
873238fd1498Szrj   if (DECL_DECLARED_INLINE_P (decl1)
873338fd1498Szrj       && DECL_UNINLINABLE (decl1)
873438fd1498Szrj       && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl1)))
873538fd1498Szrj     warning_at (loc, OPT_Wattributes,
873638fd1498Szrj 		"inline function %qD given attribute noinline",
873738fd1498Szrj 		decl1);
873838fd1498Szrj 
873938fd1498Szrj   /* Handle gnu_inline attribute.  */
874038fd1498Szrj   if (declspecs->inline_p
874138fd1498Szrj       && !flag_gnu89_inline
874238fd1498Szrj       && TREE_CODE (decl1) == FUNCTION_DECL
874338fd1498Szrj       && (lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (decl1))
874438fd1498Szrj 	  || current_function_decl))
874538fd1498Szrj     {
874638fd1498Szrj       if (declspecs->storage_class != csc_static)
874738fd1498Szrj 	DECL_EXTERNAL (decl1) = !DECL_EXTERNAL (decl1);
874838fd1498Szrj     }
874938fd1498Szrj 
875038fd1498Szrj   announce_function (decl1);
875138fd1498Szrj 
875238fd1498Szrj   if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl1))))
875338fd1498Szrj     {
875438fd1498Szrj       error_at (loc, "return type is an incomplete type");
875538fd1498Szrj       /* Make it return void instead.  */
875638fd1498Szrj       TREE_TYPE (decl1)
875738fd1498Szrj 	= build_function_type (void_type_node,
875838fd1498Szrj 			       TYPE_ARG_TYPES (TREE_TYPE (decl1)));
875938fd1498Szrj     }
876038fd1498Szrj 
876138fd1498Szrj   if (warn_about_return_type)
876238fd1498Szrj     warn_defaults_to (loc, flag_isoc99 ? OPT_Wimplicit_int
876338fd1498Szrj 			   : (warn_return_type ? OPT_Wreturn_type
876438fd1498Szrj 			      : OPT_Wimplicit_int),
876538fd1498Szrj 		      "return type defaults to %<int%>");
876638fd1498Szrj 
876738fd1498Szrj   /* Make the init_value nonzero so pushdecl knows this is not tentative.
876838fd1498Szrj      error_mark_node is replaced below (in pop_scope) with the BLOCK.  */
876938fd1498Szrj   DECL_INITIAL (decl1) = error_mark_node;
877038fd1498Szrj 
877138fd1498Szrj   /* A nested function is not global.  */
877238fd1498Szrj   if (current_function_decl != NULL_TREE)
877338fd1498Szrj     TREE_PUBLIC (decl1) = 0;
877438fd1498Szrj 
877538fd1498Szrj   /* If this definition isn't a prototype and we had a prototype declaration
877638fd1498Szrj      before, copy the arg type info from that prototype.  */
877738fd1498Szrj   old_decl = lookup_name_in_scope (DECL_NAME (decl1), current_scope);
877838fd1498Szrj   if (old_decl && TREE_CODE (old_decl) != FUNCTION_DECL)
877938fd1498Szrj     old_decl = NULL_TREE;
878038fd1498Szrj   current_function_prototype_locus = UNKNOWN_LOCATION;
878138fd1498Szrj   current_function_prototype_built_in = false;
878238fd1498Szrj   current_function_prototype_arg_types = NULL_TREE;
878338fd1498Szrj   if (!prototype_p (TREE_TYPE (decl1)))
878438fd1498Szrj     {
878538fd1498Szrj       if (old_decl != NULL_TREE
878638fd1498Szrj 	  && TREE_CODE (TREE_TYPE (old_decl)) == FUNCTION_TYPE
878738fd1498Szrj 	  && comptypes (TREE_TYPE (TREE_TYPE (decl1)),
878838fd1498Szrj 			TREE_TYPE (TREE_TYPE (old_decl))))
878938fd1498Szrj 	{
879038fd1498Szrj 	  if (stdarg_p (TREE_TYPE (old_decl)))
879138fd1498Szrj 	    {
879238fd1498Szrj 	      warning_at (loc, 0, "%q+D defined as variadic function "
879338fd1498Szrj 			  "without prototype", decl1);
879438fd1498Szrj 	      locate_old_decl (old_decl);
879538fd1498Szrj 	    }
879638fd1498Szrj 	  TREE_TYPE (decl1) = composite_type (TREE_TYPE (old_decl),
879738fd1498Szrj 					      TREE_TYPE (decl1));
879838fd1498Szrj 	  current_function_prototype_locus = DECL_SOURCE_LOCATION (old_decl);
879938fd1498Szrj 	  current_function_prototype_built_in
880038fd1498Szrj 	    = C_DECL_BUILTIN_PROTOTYPE (old_decl);
880138fd1498Szrj 	  current_function_prototype_arg_types
880238fd1498Szrj 	    = TYPE_ARG_TYPES (TREE_TYPE (decl1));
880338fd1498Szrj 	}
880438fd1498Szrj       if (TREE_PUBLIC (decl1))
880538fd1498Szrj 	{
880638fd1498Szrj 	  /* If there is an external prototype declaration of this
880738fd1498Szrj 	     function, record its location but do not copy information
880838fd1498Szrj 	     to this decl.  This may be an invisible declaration
880938fd1498Szrj 	     (built-in or in a scope which has finished) or simply
881038fd1498Szrj 	     have more refined argument types than any declaration
881138fd1498Szrj 	     found above.  */
881238fd1498Szrj 	  struct c_binding *b;
881338fd1498Szrj 	  for (b = I_SYMBOL_BINDING (DECL_NAME (decl1)); b; b = b->shadowed)
881438fd1498Szrj 	    if (B_IN_SCOPE (b, external_scope))
881538fd1498Szrj 	      break;
881638fd1498Szrj 	  if (b)
881738fd1498Szrj 	    {
881838fd1498Szrj 	      tree ext_decl, ext_type;
881938fd1498Szrj 	      ext_decl = b->decl;
882038fd1498Szrj 	      ext_type = b->u.type ? b->u.type : TREE_TYPE (ext_decl);
882138fd1498Szrj 	      if (TREE_CODE (ext_type) == FUNCTION_TYPE
882238fd1498Szrj 		  && comptypes (TREE_TYPE (TREE_TYPE (decl1)),
882338fd1498Szrj 				TREE_TYPE (ext_type)))
882438fd1498Szrj 		{
882538fd1498Szrj 		  current_function_prototype_locus
882638fd1498Szrj 		    = DECL_SOURCE_LOCATION (ext_decl);
882738fd1498Szrj 		  current_function_prototype_built_in
882838fd1498Szrj 		    = C_DECL_BUILTIN_PROTOTYPE (ext_decl);
882938fd1498Szrj 		  current_function_prototype_arg_types
883038fd1498Szrj 		    = TYPE_ARG_TYPES (ext_type);
883138fd1498Szrj 		}
883238fd1498Szrj 	    }
883338fd1498Szrj 	}
883438fd1498Szrj     }
883538fd1498Szrj 
883638fd1498Szrj   /* Optionally warn of old-fashioned def with no previous prototype.  */
883738fd1498Szrj   if (warn_strict_prototypes
883838fd1498Szrj       && old_decl != error_mark_node
883938fd1498Szrj       && !prototype_p (TREE_TYPE (decl1))
884038fd1498Szrj       && C_DECL_ISNT_PROTOTYPE (old_decl))
884138fd1498Szrj     warning_at (loc, OPT_Wstrict_prototypes,
884238fd1498Szrj 		"function declaration isn%'t a prototype");
884338fd1498Szrj   /* Optionally warn of any global def with no previous prototype.  */
884438fd1498Szrj   else if (warn_missing_prototypes
884538fd1498Szrj 	   && old_decl != error_mark_node
884638fd1498Szrj 	   && TREE_PUBLIC (decl1)
884738fd1498Szrj 	   && !MAIN_NAME_P (DECL_NAME (decl1))
884838fd1498Szrj 	   && C_DECL_ISNT_PROTOTYPE (old_decl)
884938fd1498Szrj 	   && !DECL_DECLARED_INLINE_P (decl1))
885038fd1498Szrj     warning_at (loc, OPT_Wmissing_prototypes,
885138fd1498Szrj 		"no previous prototype for %qD", decl1);
885238fd1498Szrj   /* Optionally warn of any def with no previous prototype
885338fd1498Szrj      if the function has already been used.  */
885438fd1498Szrj   else if (warn_missing_prototypes
885538fd1498Szrj 	   && old_decl != NULL_TREE
885638fd1498Szrj 	   && old_decl != error_mark_node
885738fd1498Szrj 	   && TREE_USED (old_decl)
885838fd1498Szrj 	   && !prototype_p (TREE_TYPE (old_decl)))
885938fd1498Szrj     warning_at (loc, OPT_Wmissing_prototypes,
886038fd1498Szrj 		"%qD was used with no prototype before its definition", decl1);
886138fd1498Szrj   /* Optionally warn of any global def with no previous declaration.  */
886238fd1498Szrj   else if (warn_missing_declarations
886338fd1498Szrj 	   && TREE_PUBLIC (decl1)
886438fd1498Szrj 	   && old_decl == NULL_TREE
886538fd1498Szrj 	   && !MAIN_NAME_P (DECL_NAME (decl1))
886638fd1498Szrj 	   && !DECL_DECLARED_INLINE_P (decl1))
886738fd1498Szrj     warning_at (loc, OPT_Wmissing_declarations,
886838fd1498Szrj 		"no previous declaration for %qD",
886938fd1498Szrj 		decl1);
887038fd1498Szrj   /* Optionally warn of any def with no previous declaration
887138fd1498Szrj      if the function has already been used.  */
887238fd1498Szrj   else if (warn_missing_declarations
887338fd1498Szrj 	   && old_decl != NULL_TREE
887438fd1498Szrj 	   && old_decl != error_mark_node
887538fd1498Szrj 	   && TREE_USED (old_decl)
887638fd1498Szrj 	   && C_DECL_IMPLICIT (old_decl))
887738fd1498Szrj     warning_at (loc, OPT_Wmissing_declarations,
887838fd1498Szrj 		"%qD was used with no declaration before its definition", decl1);
887938fd1498Szrj 
888038fd1498Szrj   /* This function exists in static storage.
888138fd1498Szrj      (This does not mean `static' in the C sense!)  */
888238fd1498Szrj   TREE_STATIC (decl1) = 1;
888338fd1498Szrj 
888438fd1498Szrj   /* This is the earliest point at which we might know the assembler
888538fd1498Szrj      name of the function.  Thus, if it's set before this, die horribly.  */
888638fd1498Szrj   gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl1));
888738fd1498Szrj 
888838fd1498Szrj   /* If #pragma weak was used, mark the decl weak now.  */
888938fd1498Szrj   if (current_scope == file_scope)
889038fd1498Szrj     maybe_apply_pragma_weak (decl1);
889138fd1498Szrj 
889238fd1498Szrj   /* Warn for unlikely, improbable, or stupid declarations of `main'.  */
889338fd1498Szrj   if (warn_main && MAIN_NAME_P (DECL_NAME (decl1)))
889438fd1498Szrj     {
889538fd1498Szrj       if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
889638fd1498Szrj 	  != integer_type_node)
889738fd1498Szrj 	pedwarn (loc, OPT_Wmain, "return type of %qD is not %<int%>", decl1);
889838fd1498Szrj       else if (TYPE_ATOMIC (TREE_TYPE (TREE_TYPE (decl1))))
889938fd1498Szrj 	pedwarn (loc, OPT_Wmain, "%<_Atomic%>-qualified return type of %qD",
890038fd1498Szrj 		 decl1);
890138fd1498Szrj 
890238fd1498Szrj       check_main_parameter_types (decl1);
890338fd1498Szrj 
890438fd1498Szrj       if (!TREE_PUBLIC (decl1))
890538fd1498Szrj 	pedwarn (loc, OPT_Wmain,
890638fd1498Szrj 		 "%qD is normally a non-static function", decl1);
890738fd1498Szrj     }
890838fd1498Szrj 
890938fd1498Szrj   /* Record the decl so that the function name is defined.
891038fd1498Szrj      If we already have a decl for this name, and it is a FUNCTION_DECL,
891138fd1498Szrj      use the old decl.  */
891238fd1498Szrj 
891338fd1498Szrj   current_function_decl = pushdecl (decl1);
891438fd1498Szrj 
891538fd1498Szrj   push_scope ();
891638fd1498Szrj   declare_parm_level ();
891738fd1498Szrj 
891838fd1498Szrj   restype = TREE_TYPE (TREE_TYPE (current_function_decl));
891938fd1498Szrj   resdecl = build_decl (loc, RESULT_DECL, NULL_TREE, restype);
892038fd1498Szrj   DECL_ARTIFICIAL (resdecl) = 1;
892138fd1498Szrj   DECL_IGNORED_P (resdecl) = 1;
892238fd1498Szrj   DECL_RESULT (current_function_decl) = resdecl;
892338fd1498Szrj 
892438fd1498Szrj   start_fname_decls ();
892538fd1498Szrj 
892638fd1498Szrj   return true;
892738fd1498Szrj }
892838fd1498Szrj 
892938fd1498Szrj /* Subroutine of store_parm_decls which handles new-style function
893038fd1498Szrj    definitions (prototype format). The parms already have decls, so we
893138fd1498Szrj    need only record them as in effect and complain if any redundant
893238fd1498Szrj    old-style parm decls were written.  */
893338fd1498Szrj static void
store_parm_decls_newstyle(tree fndecl,const struct c_arg_info * arg_info)893438fd1498Szrj store_parm_decls_newstyle (tree fndecl, const struct c_arg_info *arg_info)
893538fd1498Szrj {
893638fd1498Szrj   tree decl;
893738fd1498Szrj   c_arg_tag *tag;
893838fd1498Szrj   unsigned ix;
893938fd1498Szrj 
894038fd1498Szrj   if (current_scope->bindings)
894138fd1498Szrj     {
894238fd1498Szrj       error_at (DECL_SOURCE_LOCATION (fndecl),
894338fd1498Szrj 		"old-style parameter declarations in prototyped "
894438fd1498Szrj 		"function definition");
894538fd1498Szrj 
894638fd1498Szrj       /* Get rid of the old-style declarations.  */
894738fd1498Szrj       pop_scope ();
894838fd1498Szrj       push_scope ();
894938fd1498Szrj     }
895038fd1498Szrj   /* Don't issue this warning for nested functions, and don't issue this
895138fd1498Szrj      warning if we got here because ARG_INFO_TYPES was error_mark_node
895238fd1498Szrj      (this happens when a function definition has just an ellipsis in
895338fd1498Szrj      its parameter list).  */
895438fd1498Szrj   else if (!in_system_header_at (input_location)
895538fd1498Szrj 	   && !current_function_scope
895638fd1498Szrj 	   && arg_info->types != error_mark_node)
895738fd1498Szrj     warning_at (DECL_SOURCE_LOCATION (fndecl), OPT_Wtraditional,
895838fd1498Szrj 		"traditional C rejects ISO C style function definitions");
895938fd1498Szrj 
896038fd1498Szrj   /* Now make all the parameter declarations visible in the function body.
896138fd1498Szrj      We can bypass most of the grunt work of pushdecl.  */
896238fd1498Szrj   for (decl = arg_info->parms; decl; decl = DECL_CHAIN (decl))
896338fd1498Szrj     {
896438fd1498Szrj       DECL_CONTEXT (decl) = current_function_decl;
896538fd1498Szrj       if (DECL_NAME (decl))
896638fd1498Szrj 	{
896738fd1498Szrj 	  bind (DECL_NAME (decl), decl, current_scope,
896838fd1498Szrj 		/*invisible=*/false, /*nested=*/false,
896938fd1498Szrj 		UNKNOWN_LOCATION);
897038fd1498Szrj 	  if (!TREE_USED (decl))
897138fd1498Szrj 	    warn_if_shadowing (decl);
897238fd1498Szrj 	}
897338fd1498Szrj       else
897438fd1498Szrj 	error_at (DECL_SOURCE_LOCATION (decl), "parameter name omitted");
897538fd1498Szrj     }
897638fd1498Szrj 
897738fd1498Szrj   /* Record the parameter list in the function declaration.  */
897838fd1498Szrj   DECL_ARGUMENTS (fndecl) = arg_info->parms;
897938fd1498Szrj 
898038fd1498Szrj   /* Now make all the ancillary declarations visible, likewise.  */
898138fd1498Szrj   for (decl = arg_info->others; decl; decl = DECL_CHAIN (decl))
898238fd1498Szrj     {
898338fd1498Szrj       DECL_CONTEXT (decl) = current_function_decl;
898438fd1498Szrj       if (DECL_NAME (decl))
898538fd1498Szrj 	bind (DECL_NAME (decl), decl, current_scope,
898638fd1498Szrj 	      /*invisible=*/false,
898738fd1498Szrj 	      /*nested=*/(TREE_CODE (decl) == FUNCTION_DECL),
898838fd1498Szrj 	      UNKNOWN_LOCATION);
898938fd1498Szrj     }
899038fd1498Szrj 
899138fd1498Szrj   /* And all the tag declarations.  */
899238fd1498Szrj   FOR_EACH_VEC_SAFE_ELT_REVERSE (arg_info->tags, ix, tag)
899338fd1498Szrj     if (tag->id)
899438fd1498Szrj       bind (tag->id, tag->type, current_scope,
899538fd1498Szrj 	    /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION);
899638fd1498Szrj }
899738fd1498Szrj 
899838fd1498Szrj /* Subroutine of store_parm_decls which handles old-style function
899938fd1498Szrj    definitions (separate parameter list and declarations).  */
900038fd1498Szrj 
900138fd1498Szrj static void
store_parm_decls_oldstyle(tree fndecl,const struct c_arg_info * arg_info)900238fd1498Szrj store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info)
900338fd1498Szrj {
900438fd1498Szrj   struct c_binding *b;
900538fd1498Szrj   tree parm, decl, last;
900638fd1498Szrj   tree parmids = arg_info->parms;
900738fd1498Szrj   hash_set<tree> seen_args;
900838fd1498Szrj 
900938fd1498Szrj   if (!in_system_header_at (input_location))
901038fd1498Szrj     warning_at (DECL_SOURCE_LOCATION (fndecl),
901138fd1498Szrj 		OPT_Wold_style_definition, "old-style function definition");
901238fd1498Szrj 
901338fd1498Szrj   /* Match each formal parameter name with its declaration.  Save each
901438fd1498Szrj      decl in the appropriate TREE_PURPOSE slot of the parmids chain.  */
901538fd1498Szrj   for (parm = parmids; parm; parm = TREE_CHAIN (parm))
901638fd1498Szrj     {
901738fd1498Szrj       if (TREE_VALUE (parm) == NULL_TREE)
901838fd1498Szrj 	{
901938fd1498Szrj 	  error_at (DECL_SOURCE_LOCATION (fndecl),
902038fd1498Szrj 		    "parameter name missing from parameter list");
902138fd1498Szrj 	  TREE_PURPOSE (parm) = NULL_TREE;
902238fd1498Szrj 	  continue;
902338fd1498Szrj 	}
902438fd1498Szrj 
902538fd1498Szrj       b = I_SYMBOL_BINDING (TREE_VALUE (parm));
902638fd1498Szrj       if (b && B_IN_CURRENT_SCOPE (b))
902738fd1498Szrj 	{
902838fd1498Szrj 	  decl = b->decl;
902938fd1498Szrj 	  /* Skip erroneous parameters.  */
903038fd1498Szrj 	  if (decl == error_mark_node)
903138fd1498Szrj 	    continue;
903238fd1498Szrj 	  /* If we got something other than a PARM_DECL it is an error.  */
903338fd1498Szrj 	  if (TREE_CODE (decl) != PARM_DECL)
903438fd1498Szrj 	    {
903538fd1498Szrj 	      error_at (DECL_SOURCE_LOCATION (decl),
903638fd1498Szrj 			"%qD declared as a non-parameter", decl);
903738fd1498Szrj 	      continue;
903838fd1498Szrj 	    }
903938fd1498Szrj 	  /* If the declaration is already marked, we have a duplicate
904038fd1498Szrj 	     name.  Complain and ignore the duplicate.  */
904138fd1498Szrj 	  else if (seen_args.contains (decl))
904238fd1498Szrj 	    {
904338fd1498Szrj 	      error_at (DECL_SOURCE_LOCATION (decl),
904438fd1498Szrj 			"multiple parameters named %qD", decl);
904538fd1498Szrj 	      TREE_PURPOSE (parm) = NULL_TREE;
904638fd1498Szrj 	      continue;
904738fd1498Szrj 	    }
904838fd1498Szrj 	  /* If the declaration says "void", complain and turn it into
904938fd1498Szrj 	     an int.  */
905038fd1498Szrj 	  else if (VOID_TYPE_P (TREE_TYPE (decl)))
905138fd1498Szrj 	    {
905238fd1498Szrj 	      error_at (DECL_SOURCE_LOCATION (decl),
905338fd1498Szrj 			"parameter %qD declared with void type", decl);
905438fd1498Szrj 	      TREE_TYPE (decl) = integer_type_node;
905538fd1498Szrj 	      DECL_ARG_TYPE (decl) = integer_type_node;
905638fd1498Szrj 	      layout_decl (decl, 0);
905738fd1498Szrj 	    }
905838fd1498Szrj 	  warn_if_shadowing (decl);
905938fd1498Szrj 	}
906038fd1498Szrj       /* If no declaration found, default to int.  */
906138fd1498Szrj       else
906238fd1498Szrj 	{
906338fd1498Szrj 	  /* FIXME diagnostics: This should be the location of the argument,
906438fd1498Szrj 	     not the FNDECL.  E.g., for an old-style declaration
906538fd1498Szrj 
906638fd1498Szrj 	       int f10(v) { blah; }
906738fd1498Szrj 
906838fd1498Szrj 	     We should use the location of the V, not the F10.
906938fd1498Szrj 	     Unfortunately, the V is an IDENTIFIER_NODE which has no
907038fd1498Szrj 	     location.  In the future we need locations for c_arg_info
907138fd1498Szrj 	     entries.
907238fd1498Szrj 
907338fd1498Szrj 	     See gcc.dg/Wshadow-3.c for an example of this problem. */
907438fd1498Szrj 	  decl = build_decl (DECL_SOURCE_LOCATION (fndecl),
907538fd1498Szrj 			     PARM_DECL, TREE_VALUE (parm), integer_type_node);
907638fd1498Szrj 	  DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
907738fd1498Szrj 	  pushdecl (decl);
907838fd1498Szrj 	  warn_if_shadowing (decl);
907938fd1498Szrj 
908038fd1498Szrj 	  if (flag_isoc99)
908138fd1498Szrj 	    pedwarn (DECL_SOURCE_LOCATION (decl),
908238fd1498Szrj 		     OPT_Wimplicit_int, "type of %qD defaults to %<int%>",
908338fd1498Szrj 		     decl);
908438fd1498Szrj 	  else
908538fd1498Szrj 	    warning_at (DECL_SOURCE_LOCATION (decl),
908638fd1498Szrj 			OPT_Wmissing_parameter_type,
908738fd1498Szrj 			"type of %qD defaults to %<int%>", decl);
908838fd1498Szrj 	}
908938fd1498Szrj 
909038fd1498Szrj       TREE_PURPOSE (parm) = decl;
909138fd1498Szrj       seen_args.add (decl);
909238fd1498Szrj     }
909338fd1498Szrj 
909438fd1498Szrj   /* Now examine the parms chain for incomplete declarations
909538fd1498Szrj      and declarations with no corresponding names.  */
909638fd1498Szrj 
909738fd1498Szrj   for (b = current_scope->bindings; b; b = b->prev)
909838fd1498Szrj     {
909938fd1498Szrj       parm = b->decl;
910038fd1498Szrj       if (TREE_CODE (parm) != PARM_DECL)
910138fd1498Szrj 	continue;
910238fd1498Szrj 
910338fd1498Szrj       if (TREE_TYPE (parm) != error_mark_node
910438fd1498Szrj 	  && !COMPLETE_TYPE_P (TREE_TYPE (parm)))
910538fd1498Szrj 	{
910638fd1498Szrj 	  error_at (DECL_SOURCE_LOCATION (parm),
910738fd1498Szrj 		    "parameter %qD has incomplete type", parm);
910838fd1498Szrj 	  TREE_TYPE (parm) = error_mark_node;
910938fd1498Szrj 	}
911038fd1498Szrj 
911138fd1498Szrj       if (!seen_args.contains (parm))
911238fd1498Szrj 	{
911338fd1498Szrj 	  error_at (DECL_SOURCE_LOCATION (parm),
911438fd1498Szrj 		    "declaration for parameter %qD but no such parameter",
911538fd1498Szrj 		    parm);
911638fd1498Szrj 
911738fd1498Szrj 	  /* Pretend the parameter was not missing.
911838fd1498Szrj 	     This gets us to a standard state and minimizes
911938fd1498Szrj 	     further error messages.  */
912038fd1498Szrj 	  parmids = chainon (parmids, tree_cons (parm, 0, 0));
912138fd1498Szrj 	}
912238fd1498Szrj     }
912338fd1498Szrj 
912438fd1498Szrj   /* Chain the declarations together in the order of the list of
912538fd1498Szrj      names.  Store that chain in the function decl, replacing the
912638fd1498Szrj      list of names.  Update the current scope to match.  */
912738fd1498Szrj   DECL_ARGUMENTS (fndecl) = NULL_TREE;
912838fd1498Szrj 
912938fd1498Szrj   for (parm = parmids; parm; parm = TREE_CHAIN (parm))
913038fd1498Szrj     if (TREE_PURPOSE (parm))
913138fd1498Szrj       break;
913238fd1498Szrj   if (parm && TREE_PURPOSE (parm))
913338fd1498Szrj     {
913438fd1498Szrj       last = TREE_PURPOSE (parm);
913538fd1498Szrj       DECL_ARGUMENTS (fndecl) = last;
913638fd1498Szrj 
913738fd1498Szrj       for (parm = TREE_CHAIN (parm); parm; parm = TREE_CHAIN (parm))
913838fd1498Szrj 	if (TREE_PURPOSE (parm))
913938fd1498Szrj 	  {
914038fd1498Szrj 	    DECL_CHAIN (last) = TREE_PURPOSE (parm);
914138fd1498Szrj 	    last = TREE_PURPOSE (parm);
914238fd1498Szrj 	  }
914338fd1498Szrj       DECL_CHAIN (last) = NULL_TREE;
914438fd1498Szrj     }
914538fd1498Szrj 
914638fd1498Szrj   /* If there was a previous prototype,
914738fd1498Szrj      set the DECL_ARG_TYPE of each argument according to
914838fd1498Szrj      the type previously specified, and report any mismatches.  */
914938fd1498Szrj 
915038fd1498Szrj   if (current_function_prototype_arg_types)
915138fd1498Szrj     {
915238fd1498Szrj       tree type;
915338fd1498Szrj       for (parm = DECL_ARGUMENTS (fndecl),
915438fd1498Szrj 	     type = current_function_prototype_arg_types;
915538fd1498Szrj 	   parm || (type != NULL_TREE
915638fd1498Szrj 		    && TREE_VALUE (type) != error_mark_node
915738fd1498Szrj 		    && TYPE_MAIN_VARIANT (TREE_VALUE (type)) != void_type_node);
915838fd1498Szrj 	   parm = DECL_CHAIN (parm), type = TREE_CHAIN (type))
915938fd1498Szrj 	{
916038fd1498Szrj 	  if (parm == NULL_TREE
916138fd1498Szrj 	      || type == NULL_TREE
916238fd1498Szrj 	      || (TREE_VALUE (type) != error_mark_node
916338fd1498Szrj 		  && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node))
916438fd1498Szrj 	    {
916538fd1498Szrj 	      if (current_function_prototype_built_in)
916638fd1498Szrj 		warning_at (DECL_SOURCE_LOCATION (fndecl),
916738fd1498Szrj 			    0, "number of arguments doesn%'t match "
916838fd1498Szrj 			    "built-in prototype");
916938fd1498Szrj 	      else
917038fd1498Szrj 		{
917138fd1498Szrj 		  /* FIXME diagnostics: This should be the location of
917238fd1498Szrj 		     FNDECL, but there is bug when a prototype is
917338fd1498Szrj 		     declared inside function context, but defined
917438fd1498Szrj 		     outside of it (e.g., gcc.dg/pr15698-2.c).  In
917538fd1498Szrj 		     which case FNDECL gets the location of the
917638fd1498Szrj 		     prototype, not the definition.  */
917738fd1498Szrj 		  error_at (input_location,
917838fd1498Szrj 			    "number of arguments doesn%'t match prototype");
917938fd1498Szrj 
918038fd1498Szrj 		  error_at (current_function_prototype_locus,
918138fd1498Szrj 			    "prototype declaration");
918238fd1498Szrj 		}
918338fd1498Szrj 	      break;
918438fd1498Szrj 	    }
918538fd1498Szrj 	  /* Type for passing arg must be consistent with that
918638fd1498Szrj 	     declared for the arg.  ISO C says we take the unqualified
918738fd1498Szrj 	     type for parameters declared with qualified type.  */
918838fd1498Szrj 	  if (TREE_TYPE (parm) != error_mark_node
918938fd1498Szrj 	      && TREE_VALUE (type) != error_mark_node
919038fd1498Szrj 	      && ((TYPE_ATOMIC (DECL_ARG_TYPE (parm))
919138fd1498Szrj 		   != TYPE_ATOMIC (TREE_VALUE (type)))
919238fd1498Szrj 		  || !comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm)),
919338fd1498Szrj 				 TYPE_MAIN_VARIANT (TREE_VALUE (type)))))
919438fd1498Szrj 	    {
919538fd1498Szrj 	      if ((TYPE_ATOMIC (DECL_ARG_TYPE (parm))
919638fd1498Szrj 		   == TYPE_ATOMIC (TREE_VALUE (type)))
919738fd1498Szrj 		  && (TYPE_MAIN_VARIANT (TREE_TYPE (parm))
919838fd1498Szrj 		      == TYPE_MAIN_VARIANT (TREE_VALUE (type))))
919938fd1498Szrj 		{
920038fd1498Szrj 		  /* Adjust argument to match prototype.  E.g. a previous
920138fd1498Szrj 		     `int foo(float);' prototype causes
920238fd1498Szrj 		     `int foo(x) float x; {...}' to be treated like
920338fd1498Szrj 		     `int foo(float x) {...}'.  This is particularly
920438fd1498Szrj 		     useful for argument types like uid_t.  */
920538fd1498Szrj 		  DECL_ARG_TYPE (parm) = TREE_TYPE (parm);
920638fd1498Szrj 
920738fd1498Szrj 		  if (targetm.calls.promote_prototypes (TREE_TYPE (current_function_decl))
920838fd1498Szrj 		      && INTEGRAL_TYPE_P (TREE_TYPE (parm))
920938fd1498Szrj 		      && (TYPE_PRECISION (TREE_TYPE (parm))
921038fd1498Szrj 			  < TYPE_PRECISION (integer_type_node)))
921138fd1498Szrj 		    DECL_ARG_TYPE (parm)
921238fd1498Szrj 		      = c_type_promotes_to (TREE_TYPE (parm));
921338fd1498Szrj 
921438fd1498Szrj 		  /* ??? Is it possible to get here with a
921538fd1498Szrj 		     built-in prototype or will it always have
921638fd1498Szrj 		     been diagnosed as conflicting with an
921738fd1498Szrj 		     old-style definition and discarded?  */
921838fd1498Szrj 		  if (current_function_prototype_built_in)
921938fd1498Szrj 		    warning_at (DECL_SOURCE_LOCATION (parm),
922038fd1498Szrj 				OPT_Wpedantic, "promoted argument %qD "
922138fd1498Szrj 				"doesn%'t match built-in prototype", parm);
922238fd1498Szrj 		  else
922338fd1498Szrj 		    {
922438fd1498Szrj 		      pedwarn (DECL_SOURCE_LOCATION (parm),
922538fd1498Szrj 			       OPT_Wpedantic, "promoted argument %qD "
922638fd1498Szrj 			       "doesn%'t match prototype", parm);
922738fd1498Szrj 		      pedwarn (current_function_prototype_locus, OPT_Wpedantic,
922838fd1498Szrj 			       "prototype declaration");
922938fd1498Szrj 		    }
923038fd1498Szrj 		}
923138fd1498Szrj 	      else
923238fd1498Szrj 		{
923338fd1498Szrj 		  if (current_function_prototype_built_in)
923438fd1498Szrj 		    warning_at (DECL_SOURCE_LOCATION (parm),
923538fd1498Szrj 				0, "argument %qD doesn%'t match "
923638fd1498Szrj 				"built-in prototype", parm);
923738fd1498Szrj 		  else
923838fd1498Szrj 		    {
923938fd1498Szrj 		      error_at (DECL_SOURCE_LOCATION (parm),
924038fd1498Szrj 				"argument %qD doesn%'t match prototype", parm);
924138fd1498Szrj 		      error_at (current_function_prototype_locus,
924238fd1498Szrj 				"prototype declaration");
924338fd1498Szrj 		    }
924438fd1498Szrj 		}
924538fd1498Szrj 	    }
924638fd1498Szrj 	}
924738fd1498Szrj       TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = NULL_TREE;
924838fd1498Szrj     }
924938fd1498Szrj 
925038fd1498Szrj   /* Otherwise, create a prototype that would match.  */
925138fd1498Szrj 
925238fd1498Szrj   else
925338fd1498Szrj     {
925438fd1498Szrj       tree actual = NULL_TREE, last = NULL_TREE, type;
925538fd1498Szrj 
925638fd1498Szrj       for (parm = DECL_ARGUMENTS (fndecl); parm; parm = DECL_CHAIN (parm))
925738fd1498Szrj 	{
925838fd1498Szrj 	  type = tree_cons (NULL_TREE, DECL_ARG_TYPE (parm), NULL_TREE);
925938fd1498Szrj 	  if (last)
926038fd1498Szrj 	    TREE_CHAIN (last) = type;
926138fd1498Szrj 	  else
926238fd1498Szrj 	    actual = type;
926338fd1498Szrj 	  last = type;
926438fd1498Szrj 	}
926538fd1498Szrj       type = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
926638fd1498Szrj       if (last)
926738fd1498Szrj 	TREE_CHAIN (last) = type;
926838fd1498Szrj       else
926938fd1498Szrj 	actual = type;
927038fd1498Szrj 
927138fd1498Szrj       /* We are going to assign a new value for the TYPE_ACTUAL_ARG_TYPES
927238fd1498Szrj 	 of the type of this function, but we need to avoid having this
927338fd1498Szrj 	 affect the types of other similarly-typed functions, so we must
927438fd1498Szrj 	 first force the generation of an identical (but separate) type
927538fd1498Szrj 	 node for the relevant function type.  The new node we create
927638fd1498Szrj 	 will be a variant of the main variant of the original function
927738fd1498Szrj 	 type.  */
927838fd1498Szrj 
927938fd1498Szrj       TREE_TYPE (fndecl) = build_variant_type_copy (TREE_TYPE (fndecl));
928038fd1498Szrj 
928138fd1498Szrj       TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = actual;
928238fd1498Szrj     }
928338fd1498Szrj }
928438fd1498Szrj 
928538fd1498Szrj /* Store parameter declarations passed in ARG_INFO into the current
928638fd1498Szrj    function declaration.  */
928738fd1498Szrj 
928838fd1498Szrj void
store_parm_decls_from(struct c_arg_info * arg_info)928938fd1498Szrj store_parm_decls_from (struct c_arg_info *arg_info)
929038fd1498Szrj {
929138fd1498Szrj   current_function_arg_info = arg_info;
929238fd1498Szrj   store_parm_decls ();
929338fd1498Szrj }
929438fd1498Szrj 
929538fd1498Szrj /* Called by walk_tree to look for and update context-less labels.  */
929638fd1498Szrj 
929738fd1498Szrj static tree
set_labels_context_r(tree * tp,int * walk_subtrees,void * data)929838fd1498Szrj set_labels_context_r (tree *tp, int *walk_subtrees, void *data)
929938fd1498Szrj {
930038fd1498Szrj   if (TREE_CODE (*tp) == LABEL_EXPR
930138fd1498Szrj       && DECL_CONTEXT (LABEL_EXPR_LABEL (*tp)) == NULL_TREE)
930238fd1498Szrj     {
930338fd1498Szrj       DECL_CONTEXT (LABEL_EXPR_LABEL (*tp)) = static_cast<tree>(data);
930438fd1498Szrj       *walk_subtrees = 0;
930538fd1498Szrj     }
930638fd1498Szrj 
930738fd1498Szrj   return NULL_TREE;
930838fd1498Szrj }
930938fd1498Szrj 
931038fd1498Szrj /* Store the parameter declarations into the current function declaration.
931138fd1498Szrj    This is called after parsing the parameter declarations, before
931238fd1498Szrj    digesting the body of the function.
931338fd1498Szrj 
931438fd1498Szrj    For an old-style definition, construct a prototype out of the old-style
931538fd1498Szrj    parameter declarations and inject it into the function's type.  */
931638fd1498Szrj 
931738fd1498Szrj void
store_parm_decls(void)931838fd1498Szrj store_parm_decls (void)
931938fd1498Szrj {
932038fd1498Szrj   tree fndecl = current_function_decl;
932138fd1498Szrj   bool proto;
932238fd1498Szrj 
932338fd1498Szrj   /* The argument information block for FNDECL.  */
932438fd1498Szrj   struct c_arg_info *arg_info = current_function_arg_info;
932538fd1498Szrj   current_function_arg_info = 0;
932638fd1498Szrj 
932738fd1498Szrj   /* True if this definition is written with a prototype.  Note:
932838fd1498Szrj      despite C99 6.7.5.3p14, we can *not* treat an empty argument
932938fd1498Szrj      list in a function definition as equivalent to (void) -- an
933038fd1498Szrj      empty argument list specifies the function has no parameters,
933138fd1498Szrj      but only (void) sets up a prototype for future calls.  */
933238fd1498Szrj   proto = arg_info->types != 0;
933338fd1498Szrj 
933438fd1498Szrj   if (proto)
933538fd1498Szrj     store_parm_decls_newstyle (fndecl, arg_info);
933638fd1498Szrj   else
933738fd1498Szrj     store_parm_decls_oldstyle (fndecl, arg_info);
933838fd1498Szrj 
933938fd1498Szrj   /* The next call to push_scope will be a function body.  */
934038fd1498Szrj 
934138fd1498Szrj   next_is_function_body = true;
934238fd1498Szrj 
934338fd1498Szrj   /* Write a record describing this function definition to the prototypes
934438fd1498Szrj      file (if requested).  */
934538fd1498Szrj 
934638fd1498Szrj   gen_aux_info_record (fndecl, 1, 0, proto);
934738fd1498Szrj 
934838fd1498Szrj   /* Initialize the RTL code for the function.  */
934938fd1498Szrj   allocate_struct_function (fndecl, false);
935038fd1498Szrj 
935138fd1498Szrj   if (warn_unused_local_typedefs)
935238fd1498Szrj     cfun->language = ggc_cleared_alloc<language_function> ();
935338fd1498Szrj 
935438fd1498Szrj   /* Begin the statement tree for this function.  */
935538fd1498Szrj   DECL_SAVED_TREE (fndecl) = push_stmt_list ();
935638fd1498Szrj 
935738fd1498Szrj   /* ??? Insert the contents of the pending sizes list into the function
935838fd1498Szrj      to be evaluated.  The only reason left to have this is
935938fd1498Szrj 	void foo(int n, int array[n++])
936038fd1498Szrj      because we throw away the array type in favor of a pointer type, and
936138fd1498Szrj      thus won't naturally see the SAVE_EXPR containing the increment.  All
936238fd1498Szrj      other pending sizes would be handled by gimplify_parameters.  */
936338fd1498Szrj   if (arg_info->pending_sizes)
936438fd1498Szrj     {
936538fd1498Szrj       /* In very special circumstances, e.g. for code like
936638fd1498Szrj 	   _Atomic int i = 5;
936738fd1498Szrj 	   void f (int a[i += 2]) {}
936838fd1498Szrj 	 we need to execute the atomic assignment on function entry.
936938fd1498Szrj 	 But in this case, it is not just a straight store, it has the
937038fd1498Szrj 	 op= form, which means that build_atomic_assign has generated
937138fd1498Szrj 	 gotos, labels, etc.  Because at that time the function decl
937238fd1498Szrj 	 for F has not been created yet, those labels do not have any
937338fd1498Szrj 	 function context.  But we have the fndecl now, so update the
937438fd1498Szrj 	 labels accordingly.  gimplify_expr would crash otherwise.  */
937538fd1498Szrj       walk_tree_without_duplicates (&arg_info->pending_sizes,
937638fd1498Szrj 				    set_labels_context_r, fndecl);
937738fd1498Szrj       add_stmt (arg_info->pending_sizes);
937838fd1498Szrj     }
937938fd1498Szrj }
938038fd1498Szrj 
938138fd1498Szrj /* Store PARM_DECLs in PARMS into scope temporarily.  Used for
938238fd1498Szrj    c_finish_omp_declare_simd for function prototypes.  No diagnostics
938338fd1498Szrj    should be done.  */
938438fd1498Szrj 
938538fd1498Szrj void
temp_store_parm_decls(tree fndecl,tree parms)938638fd1498Szrj temp_store_parm_decls (tree fndecl, tree parms)
938738fd1498Szrj {
938838fd1498Szrj   push_scope ();
938938fd1498Szrj   for (tree p = parms; p; p = DECL_CHAIN (p))
939038fd1498Szrj     {
939138fd1498Szrj       DECL_CONTEXT (p) = fndecl;
939238fd1498Szrj       if (DECL_NAME (p))
939338fd1498Szrj 	bind (DECL_NAME (p), p, current_scope,
939438fd1498Szrj 	      /*invisible=*/false, /*nested=*/false,
939538fd1498Szrj 	      UNKNOWN_LOCATION);
939638fd1498Szrj     }
939738fd1498Szrj }
939838fd1498Szrj 
939938fd1498Szrj /* Undo what temp_store_parm_decls did.  */
940038fd1498Szrj 
940138fd1498Szrj void
temp_pop_parm_decls(void)940238fd1498Szrj temp_pop_parm_decls (void)
940338fd1498Szrj {
940438fd1498Szrj   /* Clear all bindings in this temporary scope, so that
940538fd1498Szrj      pop_scope doesn't create a BLOCK.  */
940638fd1498Szrj   struct c_binding *b = current_scope->bindings;
940738fd1498Szrj   current_scope->bindings = NULL;
940838fd1498Szrj   for (; b; b = free_binding_and_advance (b))
940938fd1498Szrj     {
941038fd1498Szrj       gcc_assert (TREE_CODE (b->decl) == PARM_DECL
941138fd1498Szrj 		  || b->decl == error_mark_node);
941238fd1498Szrj       gcc_assert (I_SYMBOL_BINDING (b->id) == b);
941338fd1498Szrj       I_SYMBOL_BINDING (b->id) = b->shadowed;
941438fd1498Szrj       if (b->shadowed && b->shadowed->u.type)
941538fd1498Szrj 	TREE_TYPE (b->shadowed->decl) = b->shadowed->u.type;
941638fd1498Szrj     }
941738fd1498Szrj   pop_scope ();
941838fd1498Szrj }
941938fd1498Szrj 
942038fd1498Szrj 
942138fd1498Szrj /* Finish up a function declaration and compile that function
942238fd1498Szrj    all the way to assembler language output.  Then free the storage
942338fd1498Szrj    for the function definition.
942438fd1498Szrj 
942538fd1498Szrj    This is called after parsing the body of the function definition.  */
942638fd1498Szrj 
942738fd1498Szrj void
finish_function(void)942838fd1498Szrj finish_function (void)
942938fd1498Szrj {
943038fd1498Szrj   tree fndecl = current_function_decl;
943138fd1498Szrj 
943238fd1498Szrj   if (c_dialect_objc ())
943338fd1498Szrj     objc_finish_function ();
943438fd1498Szrj 
943538fd1498Szrj   if (TREE_CODE (fndecl) == FUNCTION_DECL
943638fd1498Szrj       && targetm.calls.promote_prototypes (TREE_TYPE (fndecl)))
943738fd1498Szrj     {
943838fd1498Szrj       tree args = DECL_ARGUMENTS (fndecl);
943938fd1498Szrj       for (; args; args = DECL_CHAIN (args))
944038fd1498Szrj 	{
944138fd1498Szrj 	  tree type = TREE_TYPE (args);
944238fd1498Szrj 	  if (INTEGRAL_TYPE_P (type)
944338fd1498Szrj 	      && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
944438fd1498Szrj 	    DECL_ARG_TYPE (args) = c_type_promotes_to (type);
944538fd1498Szrj 	}
944638fd1498Szrj     }
944738fd1498Szrj 
944838fd1498Szrj   if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node)
944938fd1498Szrj     BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
945038fd1498Szrj 
945138fd1498Szrj   /* Must mark the RESULT_DECL as being in this function.  */
945238fd1498Szrj 
945338fd1498Szrj   if (DECL_RESULT (fndecl) && DECL_RESULT (fndecl) != error_mark_node)
945438fd1498Szrj     DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
945538fd1498Szrj 
945638fd1498Szrj   if (MAIN_NAME_P (DECL_NAME (fndecl)) && flag_hosted
945738fd1498Szrj       && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))
945838fd1498Szrj       == integer_type_node && flag_isoc99)
945938fd1498Szrj     {
946038fd1498Szrj       /* Hack.  We don't want the middle-end to warn that this return
946138fd1498Szrj 	 is unreachable, so we mark its location as special.  Using
946238fd1498Szrj 	 UNKNOWN_LOCATION has the problem that it gets clobbered in
946338fd1498Szrj 	 annotate_one_with_locus.  A cleaner solution might be to
946438fd1498Szrj 	 ensure ! should_carry_locus_p (stmt), but that needs a flag.
946538fd1498Szrj       */
946638fd1498Szrj       c_finish_return (BUILTINS_LOCATION, integer_zero_node, NULL_TREE);
946738fd1498Szrj     }
946838fd1498Szrj 
946938fd1498Szrj   /* Tie off the statement tree for this function.  */
947038fd1498Szrj   DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
947138fd1498Szrj 
947238fd1498Szrj   finish_fname_decls ();
947338fd1498Szrj 
947438fd1498Szrj   /* Complain if there's just no return statement.  */
947538fd1498Szrj   if (warn_return_type
947638fd1498Szrj       && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl))) != VOID_TYPE
947738fd1498Szrj       && !current_function_returns_value && !current_function_returns_null
947838fd1498Szrj       /* Don't complain if we are no-return.  */
947938fd1498Szrj       && !current_function_returns_abnormally
948038fd1498Szrj       /* Don't complain if we are declared noreturn.  */
948138fd1498Szrj       && !TREE_THIS_VOLATILE (fndecl)
948238fd1498Szrj       /* Don't warn for main().  */
948338fd1498Szrj       && !MAIN_NAME_P (DECL_NAME (fndecl))
948438fd1498Szrj       /* Or if they didn't actually specify a return type.  */
948538fd1498Szrj       && !C_FUNCTION_IMPLICIT_INT (fndecl)
948638fd1498Szrj       /* Normally, with -Wreturn-type, flow will complain, but we might
948738fd1498Szrj          optimize out static functions.  */
948838fd1498Szrj       && !TREE_PUBLIC (fndecl))
948938fd1498Szrj     {
949038fd1498Szrj       warning (OPT_Wreturn_type,
949138fd1498Szrj 	       "no return statement in function returning non-void");
949238fd1498Szrj       TREE_NO_WARNING (fndecl) = 1;
949338fd1498Szrj     }
949438fd1498Szrj 
949538fd1498Szrj   /* Complain about parameters that are only set, but never otherwise used.  */
949638fd1498Szrj   if (warn_unused_but_set_parameter)
949738fd1498Szrj     {
949838fd1498Szrj       tree decl;
949938fd1498Szrj 
950038fd1498Szrj       for (decl = DECL_ARGUMENTS (fndecl);
950138fd1498Szrj 	   decl;
950238fd1498Szrj 	   decl = DECL_CHAIN (decl))
950338fd1498Szrj 	if (TREE_USED (decl)
950438fd1498Szrj 	    && TREE_CODE (decl) == PARM_DECL
950538fd1498Szrj 	    && !DECL_READ_P (decl)
950638fd1498Szrj 	    && DECL_NAME (decl)
950738fd1498Szrj 	    && !DECL_ARTIFICIAL (decl)
950838fd1498Szrj 	    && !TREE_NO_WARNING (decl))
950938fd1498Szrj 	  warning_at (DECL_SOURCE_LOCATION (decl),
951038fd1498Szrj 		      OPT_Wunused_but_set_parameter,
951138fd1498Szrj 		      "parameter %qD set but not used", decl);
951238fd1498Szrj     }
951338fd1498Szrj 
951438fd1498Szrj   /* Complain about locally defined typedefs that are not used in this
951538fd1498Szrj      function.  */
951638fd1498Szrj   maybe_warn_unused_local_typedefs ();
951738fd1498Szrj 
951838fd1498Szrj   /* Possibly warn about unused parameters.  */
951938fd1498Szrj   if (warn_unused_parameter)
952038fd1498Szrj     do_warn_unused_parameter (fndecl);
952138fd1498Szrj 
952238fd1498Szrj   /* Store the end of the function, so that we get good line number
952338fd1498Szrj      info for the epilogue.  */
952438fd1498Szrj   cfun->function_end_locus = input_location;
952538fd1498Szrj 
952638fd1498Szrj   /* Finalize the ELF visibility for the function.  */
952738fd1498Szrj   c_determine_visibility (fndecl);
952838fd1498Szrj 
952938fd1498Szrj   /* For GNU C extern inline functions disregard inline limits.  */
953038fd1498Szrj   if (DECL_EXTERNAL (fndecl)
953138fd1498Szrj       && DECL_DECLARED_INLINE_P (fndecl)
953238fd1498Szrj       && (flag_gnu89_inline
953338fd1498Szrj 	  || lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (fndecl))))
953438fd1498Szrj     DECL_DISREGARD_INLINE_LIMITS (fndecl) = 1;
953538fd1498Szrj 
953638fd1498Szrj   /* Genericize before inlining.  Delay genericizing nested functions
953738fd1498Szrj      until their parent function is genericized.  Since finalizing
953838fd1498Szrj      requires GENERIC, delay that as well.  */
953938fd1498Szrj 
954038fd1498Szrj   if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node
954138fd1498Szrj       && !undef_nested_function)
954238fd1498Szrj     {
954338fd1498Szrj       if (!decl_function_context (fndecl))
954438fd1498Szrj 	{
954538fd1498Szrj 	  invoke_plugin_callbacks (PLUGIN_PRE_GENERICIZE, fndecl);
954638fd1498Szrj 	  c_genericize (fndecl);
954738fd1498Szrj 
954838fd1498Szrj 	  /* ??? Objc emits functions after finalizing the compilation unit.
954938fd1498Szrj 	     This should be cleaned up later and this conditional removed.  */
955038fd1498Szrj 	  if (symtab->global_info_ready)
955138fd1498Szrj 	    {
955238fd1498Szrj 	      cgraph_node::add_new_function (fndecl, false);
955338fd1498Szrj 	      return;
955438fd1498Szrj 	    }
955538fd1498Szrj 	  cgraph_node::finalize_function (fndecl, false);
955638fd1498Szrj 	}
955738fd1498Szrj       else
955838fd1498Szrj 	{
955938fd1498Szrj 	  /* Register this function with cgraph just far enough to get it
956038fd1498Szrj 	    added to our parent's nested function list.  Handy, since the
956138fd1498Szrj 	    C front end doesn't have such a list.  */
956238fd1498Szrj 	  (void) cgraph_node::get_create (fndecl);
956338fd1498Szrj 	}
956438fd1498Szrj     }
956538fd1498Szrj 
956638fd1498Szrj   if (!decl_function_context (fndecl))
956738fd1498Szrj     undef_nested_function = false;
956838fd1498Szrj 
956938fd1498Szrj   if (cfun->language != NULL)
957038fd1498Szrj     {
957138fd1498Szrj       ggc_free (cfun->language);
957238fd1498Szrj       cfun->language = NULL;
957338fd1498Szrj     }
957438fd1498Szrj 
957538fd1498Szrj   /* We're leaving the context of this function, so zap cfun.
957638fd1498Szrj      It's still in DECL_STRUCT_FUNCTION, and we'll restore it in
957738fd1498Szrj      tree_rest_of_compilation.  */
957838fd1498Szrj   set_cfun (NULL);
957938fd1498Szrj   invoke_plugin_callbacks (PLUGIN_FINISH_PARSE_FUNCTION, current_function_decl);
958038fd1498Szrj   current_function_decl = NULL;
958138fd1498Szrj }
958238fd1498Szrj 
958338fd1498Szrj /* Check the declarations given in a for-loop for satisfying the C99
958438fd1498Szrj    constraints.  If exactly one such decl is found, return it.  LOC is
958538fd1498Szrj    the location of the opening parenthesis of the for loop.  The last
958638fd1498Szrj    parameter allows you to control the "for loop initial declarations
958738fd1498Szrj    are only allowed in C99 mode".  Normally, you should pass
958838fd1498Szrj    flag_isoc99 as that parameter.  But in some cases (Objective-C
958938fd1498Szrj    foreach loop, for example) we want to run the checks in this
959038fd1498Szrj    function even if not in C99 mode, so we allow the caller to turn
959138fd1498Szrj    off the error about not being in C99 mode.
959238fd1498Szrj */
959338fd1498Szrj 
959438fd1498Szrj tree
check_for_loop_decls(location_t loc,bool turn_off_iso_c99_error)959538fd1498Szrj check_for_loop_decls (location_t loc, bool turn_off_iso_c99_error)
959638fd1498Szrj {
959738fd1498Szrj   struct c_binding *b;
959838fd1498Szrj   tree one_decl = NULL_TREE;
959938fd1498Szrj   int n_decls = 0;
960038fd1498Szrj 
960138fd1498Szrj   if (!turn_off_iso_c99_error)
960238fd1498Szrj     {
960338fd1498Szrj       static bool hint = true;
960438fd1498Szrj       /* If we get here, declarations have been used in a for loop without
960538fd1498Szrj 	 the C99 for loop scope.  This doesn't make much sense, so don't
960638fd1498Szrj 	 allow it.  */
960738fd1498Szrj       error_at (loc, "%<for%> loop initial declarations "
960838fd1498Szrj 		"are only allowed in C99 or C11 mode");
960938fd1498Szrj       if (hint)
961038fd1498Szrj 	{
961138fd1498Szrj 	  inform (loc,
961238fd1498Szrj 		  "use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 "
961338fd1498Szrj 		  "to compile your code");
961438fd1498Szrj 	  hint = false;
961538fd1498Szrj 	}
961638fd1498Szrj       return NULL_TREE;
961738fd1498Szrj     }
961838fd1498Szrj   /* C99 subclause 6.8.5 paragraph 3:
961938fd1498Szrj 
962038fd1498Szrj        [#3]  The  declaration  part  of  a for statement shall only
962138fd1498Szrj        declare identifiers for objects having storage class auto or
962238fd1498Szrj        register.
962338fd1498Szrj 
962438fd1498Szrj      It isn't clear whether, in this sentence, "identifiers" binds to
962538fd1498Szrj      "shall only declare" or to "objects" - that is, whether all identifiers
962638fd1498Szrj      declared must be identifiers for objects, or whether the restriction
962738fd1498Szrj      only applies to those that are.  (A question on this in comp.std.c
962838fd1498Szrj      in November 2000 received no answer.)  We implement the strictest
962938fd1498Szrj      interpretation, to avoid creating an extension which later causes
963038fd1498Szrj      problems.  */
963138fd1498Szrj 
963238fd1498Szrj   for (b = current_scope->bindings; b; b = b->prev)
963338fd1498Szrj     {
963438fd1498Szrj       tree id = b->id;
963538fd1498Szrj       tree decl = b->decl;
963638fd1498Szrj 
963738fd1498Szrj       if (!id)
963838fd1498Szrj 	continue;
963938fd1498Szrj 
964038fd1498Szrj       switch (TREE_CODE (decl))
964138fd1498Szrj 	{
964238fd1498Szrj 	case VAR_DECL:
964338fd1498Szrj 	  {
964438fd1498Szrj 	    location_t decl_loc = DECL_SOURCE_LOCATION (decl);
964538fd1498Szrj 	    if (TREE_STATIC (decl))
964638fd1498Szrj 	      error_at (decl_loc,
964738fd1498Szrj 			"declaration of static variable %qD in %<for%> loop "
964838fd1498Szrj 			"initial declaration", decl);
964938fd1498Szrj 	    else if (DECL_EXTERNAL (decl))
965038fd1498Szrj 	      error_at (decl_loc,
965138fd1498Szrj 			"declaration of %<extern%> variable %qD in %<for%> loop "
965238fd1498Szrj 			"initial declaration", decl);
965338fd1498Szrj 	  }
965438fd1498Szrj 	  break;
965538fd1498Szrj 
965638fd1498Szrj 	case RECORD_TYPE:
965738fd1498Szrj 	  error_at (loc,
965838fd1498Szrj 		    "%<struct %E%> declared in %<for%> loop initial "
965938fd1498Szrj 		    "declaration", id);
966038fd1498Szrj 	  break;
966138fd1498Szrj 	case UNION_TYPE:
966238fd1498Szrj 	  error_at (loc,
966338fd1498Szrj 		    "%<union %E%> declared in %<for%> loop initial declaration",
966438fd1498Szrj 		    id);
966538fd1498Szrj 	  break;
966638fd1498Szrj 	case ENUMERAL_TYPE:
966738fd1498Szrj 	  error_at (loc, "%<enum %E%> declared in %<for%> loop "
966838fd1498Szrj 		    "initial declaration", id);
966938fd1498Szrj 	  break;
967038fd1498Szrj 	default:
967138fd1498Szrj 	  error_at (loc, "declaration of non-variable "
967238fd1498Szrj 		    "%qD in %<for%> loop initial declaration", decl);
967338fd1498Szrj 	}
967438fd1498Szrj 
967538fd1498Szrj       n_decls++;
967638fd1498Szrj       one_decl = decl;
967738fd1498Szrj     }
967838fd1498Szrj 
967938fd1498Szrj   return n_decls == 1 ? one_decl : NULL_TREE;
968038fd1498Szrj }
968138fd1498Szrj 
968238fd1498Szrj /* Save and reinitialize the variables
968338fd1498Szrj    used during compilation of a C function.  */
968438fd1498Szrj 
968538fd1498Szrj void
c_push_function_context(void)968638fd1498Szrj c_push_function_context (void)
968738fd1498Szrj {
968838fd1498Szrj   struct language_function *p = cfun->language;
968938fd1498Szrj   /* cfun->language might have been already allocated by the use of
969038fd1498Szrj      -Wunused-local-typedefs.  In that case, just re-use it.  */
969138fd1498Szrj   if (p == NULL)
969238fd1498Szrj     cfun->language = p = ggc_cleared_alloc<language_function> ();
969338fd1498Szrj 
969438fd1498Szrj   p->base.x_stmt_tree = c_stmt_tree;
969538fd1498Szrj   c_stmt_tree.x_cur_stmt_list = vec_safe_copy (c_stmt_tree.x_cur_stmt_list);
969638fd1498Szrj   p->x_break_label = c_break_label;
969738fd1498Szrj   p->x_cont_label = c_cont_label;
969838fd1498Szrj   p->x_switch_stack = c_switch_stack;
969938fd1498Szrj   p->arg_info = current_function_arg_info;
970038fd1498Szrj   p->returns_value = current_function_returns_value;
970138fd1498Szrj   p->returns_null = current_function_returns_null;
970238fd1498Szrj   p->returns_abnormally = current_function_returns_abnormally;
970338fd1498Szrj   p->warn_about_return_type = warn_about_return_type;
970438fd1498Szrj 
970538fd1498Szrj   push_function_context ();
970638fd1498Szrj }
970738fd1498Szrj 
970838fd1498Szrj /* Restore the variables used during compilation of a C function.  */
970938fd1498Szrj 
971038fd1498Szrj void
c_pop_function_context(void)971138fd1498Szrj c_pop_function_context (void)
971238fd1498Szrj {
971338fd1498Szrj   struct language_function *p;
971438fd1498Szrj 
971538fd1498Szrj   pop_function_context ();
971638fd1498Szrj   p = cfun->language;
971738fd1498Szrj 
971838fd1498Szrj   /* When -Wunused-local-typedefs is in effect, cfun->languages is
971938fd1498Szrj      used to store data throughout the life time of the current cfun,
972038fd1498Szrj      So don't deallocate it.  */
972138fd1498Szrj   if (!warn_unused_local_typedefs)
972238fd1498Szrj     cfun->language = NULL;
972338fd1498Szrj 
972438fd1498Szrj   if (DECL_STRUCT_FUNCTION (current_function_decl) == 0
972538fd1498Szrj       && DECL_SAVED_TREE (current_function_decl) == NULL_TREE)
972638fd1498Szrj     {
972738fd1498Szrj       /* Stop pointing to the local nodes about to be freed.  */
972838fd1498Szrj       /* But DECL_INITIAL must remain nonzero so we know this
972938fd1498Szrj 	 was an actual function definition.  */
973038fd1498Szrj       DECL_INITIAL (current_function_decl) = error_mark_node;
973138fd1498Szrj       DECL_ARGUMENTS (current_function_decl) = NULL_TREE;
973238fd1498Szrj     }
973338fd1498Szrj 
973438fd1498Szrj   c_stmt_tree = p->base.x_stmt_tree;
973538fd1498Szrj   p->base.x_stmt_tree.x_cur_stmt_list = NULL;
973638fd1498Szrj   c_break_label = p->x_break_label;
973738fd1498Szrj   c_cont_label = p->x_cont_label;
973838fd1498Szrj   c_switch_stack = p->x_switch_stack;
973938fd1498Szrj   current_function_arg_info = p->arg_info;
974038fd1498Szrj   current_function_returns_value = p->returns_value;
974138fd1498Szrj   current_function_returns_null = p->returns_null;
974238fd1498Szrj   current_function_returns_abnormally = p->returns_abnormally;
974338fd1498Szrj   warn_about_return_type = p->warn_about_return_type;
974438fd1498Szrj }
974538fd1498Szrj 
974638fd1498Szrj /* The functions below are required for functionality of doing
974738fd1498Szrj    function at once processing in the C front end. Currently these
974838fd1498Szrj    functions are not called from anywhere in the C front end, but as
974938fd1498Szrj    these changes continue, that will change.  */
975038fd1498Szrj 
975138fd1498Szrj /* Returns the stmt_tree (if any) to which statements are currently
975238fd1498Szrj    being added.  If there is no active statement-tree, NULL is
975338fd1498Szrj    returned.  */
975438fd1498Szrj 
975538fd1498Szrj stmt_tree
current_stmt_tree(void)975638fd1498Szrj current_stmt_tree (void)
975738fd1498Szrj {
975838fd1498Szrj   return &c_stmt_tree;
975938fd1498Szrj }
976038fd1498Szrj 
976138fd1498Szrj /* Return the global value of T as a symbol.  */
976238fd1498Szrj 
976338fd1498Szrj tree
identifier_global_value(tree t)976438fd1498Szrj identifier_global_value	(tree t)
976538fd1498Szrj {
976638fd1498Szrj   struct c_binding *b;
976738fd1498Szrj 
976838fd1498Szrj   for (b = I_SYMBOL_BINDING (t); b; b = b->shadowed)
976938fd1498Szrj     if (B_IN_FILE_SCOPE (b) || B_IN_EXTERNAL_SCOPE (b))
977038fd1498Szrj       return b->decl;
977138fd1498Szrj 
977238fd1498Szrj   return NULL_TREE;
977338fd1498Szrj }
977438fd1498Szrj 
977538fd1498Szrj /* In C, the only C-linkage public declaration is at file scope.  */
977638fd1498Szrj 
977738fd1498Szrj tree
c_linkage_bindings(tree name)977838fd1498Szrj c_linkage_bindings (tree name)
977938fd1498Szrj {
978038fd1498Szrj   return identifier_global_value (name);
978138fd1498Szrj }
978238fd1498Szrj 
978338fd1498Szrj /* Record a builtin type for C.  If NAME is non-NULL, it is the name used;
978438fd1498Szrj    otherwise the name is found in ridpointers from RID_INDEX.  */
978538fd1498Szrj 
978638fd1498Szrj void
record_builtin_type(enum rid rid_index,const char * name,tree type)978738fd1498Szrj record_builtin_type (enum rid rid_index, const char *name, tree type)
978838fd1498Szrj {
978938fd1498Szrj   tree id, decl;
979038fd1498Szrj   if (name == 0)
979138fd1498Szrj     id = ridpointers[(int) rid_index];
979238fd1498Szrj   else
979338fd1498Szrj     id = get_identifier (name);
979438fd1498Szrj   decl = build_decl (UNKNOWN_LOCATION, TYPE_DECL, id, type);
979538fd1498Szrj   pushdecl (decl);
979638fd1498Szrj   if (debug_hooks->type_decl)
979738fd1498Szrj     debug_hooks->type_decl (decl, false);
979838fd1498Szrj }
979938fd1498Szrj 
980038fd1498Szrj /* Build the void_list_node (void_type_node having been created).  */
980138fd1498Szrj tree
build_void_list_node(void)980238fd1498Szrj build_void_list_node (void)
980338fd1498Szrj {
980438fd1498Szrj   tree t = build_tree_list (NULL_TREE, void_type_node);
980538fd1498Szrj   return t;
980638fd1498Szrj }
980738fd1498Szrj 
980838fd1498Szrj /* Return a c_parm structure with the given SPECS, ATTRS and DECLARATOR.  */
980938fd1498Szrj 
981038fd1498Szrj struct c_parm *
build_c_parm(struct c_declspecs * specs,tree attrs,struct c_declarator * declarator,location_t loc)981138fd1498Szrj build_c_parm (struct c_declspecs *specs, tree attrs,
981238fd1498Szrj 	      struct c_declarator *declarator,
981338fd1498Szrj 	      location_t loc)
981438fd1498Szrj {
981538fd1498Szrj   struct c_parm *ret = XOBNEW (&parser_obstack, struct c_parm);
981638fd1498Szrj   ret->specs = specs;
981738fd1498Szrj   ret->attrs = attrs;
981838fd1498Szrj   ret->declarator = declarator;
981938fd1498Szrj   ret->loc = loc;
982038fd1498Szrj   return ret;
982138fd1498Szrj }
982238fd1498Szrj 
982338fd1498Szrj /* Return a declarator with nested attributes.  TARGET is the inner
982438fd1498Szrj    declarator to which these attributes apply.  ATTRS are the
982538fd1498Szrj    attributes.  */
982638fd1498Szrj 
982738fd1498Szrj struct c_declarator *
build_attrs_declarator(tree attrs,struct c_declarator * target)982838fd1498Szrj build_attrs_declarator (tree attrs, struct c_declarator *target)
982938fd1498Szrj {
983038fd1498Szrj   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
983138fd1498Szrj   ret->kind = cdk_attrs;
983238fd1498Szrj   ret->declarator = target;
983338fd1498Szrj   ret->u.attrs = attrs;
983438fd1498Szrj   return ret;
983538fd1498Szrj }
983638fd1498Szrj 
983738fd1498Szrj /* Return a declarator for a function with arguments specified by ARGS
983838fd1498Szrj    and return type specified by TARGET.  */
983938fd1498Szrj 
984038fd1498Szrj struct c_declarator *
build_function_declarator(struct c_arg_info * args,struct c_declarator * target)984138fd1498Szrj build_function_declarator (struct c_arg_info *args,
984238fd1498Szrj 			   struct c_declarator *target)
984338fd1498Szrj {
984438fd1498Szrj   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
984538fd1498Szrj   ret->kind = cdk_function;
984638fd1498Szrj   ret->declarator = target;
984738fd1498Szrj   ret->u.arg_info = args;
984838fd1498Szrj   return ret;
984938fd1498Szrj }
985038fd1498Szrj 
985138fd1498Szrj /* Return a declarator for the identifier IDENT (which may be
985238fd1498Szrj    NULL_TREE for an abstract declarator).  */
985338fd1498Szrj 
985438fd1498Szrj struct c_declarator *
build_id_declarator(tree ident)985538fd1498Szrj build_id_declarator (tree ident)
985638fd1498Szrj {
985738fd1498Szrj   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
985838fd1498Szrj   ret->kind = cdk_id;
985938fd1498Szrj   ret->declarator = 0;
986038fd1498Szrj   ret->u.id = ident;
986138fd1498Szrj   /* Default value - may get reset to a more precise location. */
986238fd1498Szrj   ret->id_loc = input_location;
986338fd1498Szrj   return ret;
986438fd1498Szrj }
986538fd1498Szrj 
986638fd1498Szrj /* Return something to represent absolute declarators containing a *.
986738fd1498Szrj    TARGET is the absolute declarator that the * contains.
986838fd1498Szrj    TYPE_QUALS_ATTRS is a structure for type qualifiers and attributes
986938fd1498Szrj    to apply to the pointer type.  */
987038fd1498Szrj 
987138fd1498Szrj struct c_declarator *
make_pointer_declarator(struct c_declspecs * type_quals_attrs,struct c_declarator * target)987238fd1498Szrj make_pointer_declarator (struct c_declspecs *type_quals_attrs,
987338fd1498Szrj 			 struct c_declarator *target)
987438fd1498Szrj {
987538fd1498Szrj   tree attrs;
987638fd1498Szrj   int quals = 0;
987738fd1498Szrj   struct c_declarator *itarget = target;
987838fd1498Szrj   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
987938fd1498Szrj   if (type_quals_attrs)
988038fd1498Szrj     {
988138fd1498Szrj       attrs = type_quals_attrs->attrs;
988238fd1498Szrj       quals = quals_from_declspecs (type_quals_attrs);
988338fd1498Szrj       if (attrs != NULL_TREE)
988438fd1498Szrj 	itarget = build_attrs_declarator (attrs, target);
988538fd1498Szrj     }
988638fd1498Szrj   ret->kind = cdk_pointer;
988738fd1498Szrj   ret->declarator = itarget;
988838fd1498Szrj   ret->u.pointer_quals = quals;
988938fd1498Szrj   return ret;
989038fd1498Szrj }
989138fd1498Szrj 
989238fd1498Szrj /* Return a pointer to a structure for an empty list of declaration
989338fd1498Szrj    specifiers.  */
989438fd1498Szrj 
989538fd1498Szrj struct c_declspecs *
build_null_declspecs(void)989638fd1498Szrj build_null_declspecs (void)
989738fd1498Szrj {
989838fd1498Szrj   struct c_declspecs *ret = XOBNEW (&parser_obstack, struct c_declspecs);
989938fd1498Szrj   memset (ret, 0, sizeof *ret);
990038fd1498Szrj   ret->align_log = -1;
990138fd1498Szrj   ret->typespec_word = cts_none;
990238fd1498Szrj   ret->storage_class = csc_none;
990338fd1498Szrj   ret->expr_const_operands = true;
990438fd1498Szrj   ret->typespec_kind = ctsk_none;
990538fd1498Szrj   ret->address_space = ADDR_SPACE_GENERIC;
990638fd1498Szrj   return ret;
990738fd1498Szrj }
990838fd1498Szrj 
990938fd1498Szrj /* Add the address space ADDRSPACE to the declaration specifiers
991038fd1498Szrj    SPECS, returning SPECS.  */
991138fd1498Szrj 
991238fd1498Szrj struct c_declspecs *
declspecs_add_addrspace(source_location location,struct c_declspecs * specs,addr_space_t as)991338fd1498Szrj declspecs_add_addrspace (source_location location,
991438fd1498Szrj 			 struct c_declspecs *specs, addr_space_t as)
991538fd1498Szrj {
991638fd1498Szrj   specs->non_sc_seen_p = true;
991738fd1498Szrj   specs->declspecs_seen_p = true;
991838fd1498Szrj 
991938fd1498Szrj   if (!ADDR_SPACE_GENERIC_P (specs->address_space)
992038fd1498Szrj       && specs->address_space != as)
992138fd1498Szrj     error ("incompatible address space qualifiers %qs and %qs",
992238fd1498Szrj 	   c_addr_space_name (as),
992338fd1498Szrj 	   c_addr_space_name (specs->address_space));
992438fd1498Szrj   else
992538fd1498Szrj     {
992638fd1498Szrj       specs->address_space = as;
992738fd1498Szrj       specs->locations[cdw_address_space] = location;
992838fd1498Szrj     }
992938fd1498Szrj   return specs;
993038fd1498Szrj }
993138fd1498Szrj 
993238fd1498Szrj /* Add the type qualifier QUAL to the declaration specifiers SPECS,
993338fd1498Szrj    returning SPECS.  */
993438fd1498Szrj 
993538fd1498Szrj struct c_declspecs *
declspecs_add_qual(source_location loc,struct c_declspecs * specs,tree qual)993638fd1498Szrj declspecs_add_qual (source_location loc,
993738fd1498Szrj 		    struct c_declspecs *specs, tree qual)
993838fd1498Szrj {
993938fd1498Szrj   enum rid i;
994038fd1498Szrj   bool dupe = false;
994138fd1498Szrj   specs->non_sc_seen_p = true;
994238fd1498Szrj   specs->declspecs_seen_p = true;
994338fd1498Szrj   gcc_assert (TREE_CODE (qual) == IDENTIFIER_NODE
994438fd1498Szrj 	      && C_IS_RESERVED_WORD (qual));
994538fd1498Szrj   i = C_RID_CODE (qual);
994638fd1498Szrj   location_t prev_loc = UNKNOWN_LOCATION;
994738fd1498Szrj   switch (i)
994838fd1498Szrj     {
994938fd1498Szrj     case RID_CONST:
995038fd1498Szrj       dupe = specs->const_p;
995138fd1498Szrj       specs->const_p = true;
995238fd1498Szrj       prev_loc = specs->locations[cdw_const];
995338fd1498Szrj       specs->locations[cdw_const] = loc;
995438fd1498Szrj       break;
995538fd1498Szrj     case RID_VOLATILE:
995638fd1498Szrj       dupe = specs->volatile_p;
995738fd1498Szrj       specs->volatile_p = true;
995838fd1498Szrj       prev_loc = specs->locations[cdw_volatile];
995938fd1498Szrj       specs->locations[cdw_volatile] = loc;
996038fd1498Szrj       break;
996138fd1498Szrj     case RID_RESTRICT:
996238fd1498Szrj       dupe = specs->restrict_p;
996338fd1498Szrj       specs->restrict_p = true;
996438fd1498Szrj       prev_loc = specs->locations[cdw_restrict];
996538fd1498Szrj       specs->locations[cdw_restrict] = loc;
996638fd1498Szrj       break;
996738fd1498Szrj     case RID_ATOMIC:
996838fd1498Szrj       dupe = specs->atomic_p;
996938fd1498Szrj       specs->atomic_p = true;
997038fd1498Szrj       prev_loc = specs->locations[cdw_atomic];
997138fd1498Szrj       specs->locations[cdw_atomic] = loc;
997238fd1498Szrj       break;
997338fd1498Szrj     default:
997438fd1498Szrj       gcc_unreachable ();
997538fd1498Szrj     }
997638fd1498Szrj   if (dupe)
997738fd1498Szrj     {
997838fd1498Szrj       bool warned = pedwarn_c90 (loc, OPT_Wpedantic,
997938fd1498Szrj 				 "duplicate %qE declaration specifier", qual);
998038fd1498Szrj       if (!warned
998138fd1498Szrj 	  && warn_duplicate_decl_specifier
998238fd1498Szrj 	  && prev_loc >= RESERVED_LOCATION_COUNT
998338fd1498Szrj 	  && !from_macro_expansion_at (prev_loc)
998438fd1498Szrj 	  && !from_macro_expansion_at (loc))
998538fd1498Szrj 	warning_at (loc, OPT_Wduplicate_decl_specifier,
998638fd1498Szrj 		    "duplicate %qE declaration specifier", qual);
998738fd1498Szrj     }
998838fd1498Szrj   return specs;
998938fd1498Szrj }
999038fd1498Szrj 
999138fd1498Szrj /* Add the type specifier TYPE to the declaration specifiers SPECS,
999238fd1498Szrj    returning SPECS.  */
999338fd1498Szrj 
999438fd1498Szrj struct c_declspecs *
declspecs_add_type(location_t loc,struct c_declspecs * specs,struct c_typespec spec)999538fd1498Szrj declspecs_add_type (location_t loc, struct c_declspecs *specs,
999638fd1498Szrj 		    struct c_typespec spec)
999738fd1498Szrj {
999838fd1498Szrj   tree type = spec.spec;
999938fd1498Szrj   specs->non_sc_seen_p = true;
1000038fd1498Szrj   specs->declspecs_seen_p = true;
1000138fd1498Szrj   specs->typespec_kind = spec.kind;
1000238fd1498Szrj   if (TREE_DEPRECATED (type))
1000338fd1498Szrj     specs->deprecated_p = true;
1000438fd1498Szrj 
1000538fd1498Szrj   /* Handle type specifier keywords.  */
1000638fd1498Szrj   if (TREE_CODE (type) == IDENTIFIER_NODE
1000738fd1498Szrj       && C_IS_RESERVED_WORD (type)
1000838fd1498Szrj       && C_RID_CODE (type) != RID_CXX_COMPAT_WARN)
1000938fd1498Szrj     {
1001038fd1498Szrj       enum rid i = C_RID_CODE (type);
1001138fd1498Szrj       if (specs->type)
1001238fd1498Szrj 	{
1001338fd1498Szrj 	  error_at (loc, "two or more data types in declaration specifiers");
1001438fd1498Szrj 	  return specs;
1001538fd1498Szrj 	}
1001638fd1498Szrj       if ((int) i <= (int) RID_LAST_MODIFIER)
1001738fd1498Szrj 	{
1001838fd1498Szrj 	  /* "long", "short", "signed", "unsigned", "_Complex" or "_Sat".  */
1001938fd1498Szrj 	  bool dupe = false;
1002038fd1498Szrj 	  switch (i)
1002138fd1498Szrj 	    {
1002238fd1498Szrj 	    case RID_LONG:
1002338fd1498Szrj 	      if (specs->long_long_p)
1002438fd1498Szrj 		{
1002538fd1498Szrj 		  error_at (loc, "%<long long long%> is too long for GCC");
1002638fd1498Szrj 		  break;
1002738fd1498Szrj 		}
1002838fd1498Szrj 	      if (specs->long_p)
1002938fd1498Szrj 		{
1003038fd1498Szrj 		  if (specs->typespec_word == cts_double)
1003138fd1498Szrj 		    {
1003238fd1498Szrj 		      error_at (loc,
1003338fd1498Szrj 				("both %<long long%> and %<double%> in "
1003438fd1498Szrj 				 "declaration specifiers"));
1003538fd1498Szrj 		      break;
1003638fd1498Szrj 		    }
1003738fd1498Szrj 		  pedwarn_c90 (loc, OPT_Wlong_long,
1003838fd1498Szrj 			       "ISO C90 does not support %<long long%>");
1003938fd1498Szrj 		  specs->long_long_p = 1;
1004038fd1498Szrj 		  specs->locations[cdw_long_long] = loc;
1004138fd1498Szrj 		  break;
1004238fd1498Szrj 		}
1004338fd1498Szrj 	      if (specs->short_p)
1004438fd1498Szrj 		error_at (loc,
1004538fd1498Szrj 			  ("both %<long%> and %<short%> in "
1004638fd1498Szrj 			   "declaration specifiers"));
1004738fd1498Szrj 	      else if (specs->typespec_word == cts_auto_type)
1004838fd1498Szrj 		error_at (loc,
1004938fd1498Szrj 			  ("both %<long%> and %<__auto_type%> in "
1005038fd1498Szrj 			   "declaration specifiers"));
1005138fd1498Szrj 	      else if (specs->typespec_word == cts_void)
1005238fd1498Szrj 		error_at (loc,
1005338fd1498Szrj 			  ("both %<long%> and %<void%> in "
1005438fd1498Szrj 			   "declaration specifiers"));
1005538fd1498Szrj 	      else if (specs->typespec_word == cts_int_n)
1005638fd1498Szrj 		  error_at (loc,
1005738fd1498Szrj 			    ("both %<long%> and %<__int%d%> in "
1005838fd1498Szrj 			     "declaration specifiers"),
1005938fd1498Szrj 			    int_n_data[specs->int_n_idx].bitsize);
1006038fd1498Szrj 	      else if (specs->typespec_word == cts_bool)
1006138fd1498Szrj 		error_at (loc,
1006238fd1498Szrj 			  ("both %<long%> and %<_Bool%> in "
1006338fd1498Szrj 			   "declaration specifiers"));
1006438fd1498Szrj 	      else if (specs->typespec_word == cts_char)
1006538fd1498Szrj 		error_at (loc,
1006638fd1498Szrj 			  ("both %<long%> and %<char%> in "
1006738fd1498Szrj 			   "declaration specifiers"));
1006838fd1498Szrj 	      else if (specs->typespec_word == cts_float)
1006938fd1498Szrj 		error_at (loc,
1007038fd1498Szrj 			  ("both %<long%> and %<float%> in "
1007138fd1498Szrj 			   "declaration specifiers"));
1007238fd1498Szrj 	      else if (specs->typespec_word == cts_floatn_nx)
1007338fd1498Szrj 		error_at (loc,
1007438fd1498Szrj 			  ("both %<long%> and %<_Float%d%s%> in "
1007538fd1498Szrj 			   "declaration specifiers"),
1007638fd1498Szrj 			  floatn_nx_types[specs->floatn_nx_idx].n,
1007738fd1498Szrj 			  (floatn_nx_types[specs->floatn_nx_idx].extended
1007838fd1498Szrj 			   ? "x"
1007938fd1498Szrj 			   : ""));
1008038fd1498Szrj 	      else if (specs->typespec_word == cts_dfloat32)
1008138fd1498Szrj 		error_at (loc,
1008238fd1498Szrj 			  ("both %<long%> and %<_Decimal32%> in "
1008338fd1498Szrj 			   "declaration specifiers"));
1008438fd1498Szrj 	      else if (specs->typespec_word == cts_dfloat64)
1008538fd1498Szrj 		error_at (loc,
1008638fd1498Szrj 			  ("both %<long%> and %<_Decimal64%> in "
1008738fd1498Szrj 			   "declaration specifiers"));
1008838fd1498Szrj 	      else if (specs->typespec_word == cts_dfloat128)
1008938fd1498Szrj 		error_at (loc,
1009038fd1498Szrj 			  ("both %<long%> and %<_Decimal128%> in "
1009138fd1498Szrj 			   "declaration specifiers"));
1009238fd1498Szrj 	      else
1009338fd1498Szrj 		{
1009438fd1498Szrj 		  specs->long_p = true;
1009538fd1498Szrj 		  specs->locations[cdw_long] = loc;
1009638fd1498Szrj 		}
1009738fd1498Szrj 	      break;
1009838fd1498Szrj 	    case RID_SHORT:
1009938fd1498Szrj 	      dupe = specs->short_p;
1010038fd1498Szrj 	      if (specs->long_p)
1010138fd1498Szrj 		error_at (loc,
1010238fd1498Szrj 			  ("both %<long%> and %<short%> in "
1010338fd1498Szrj 			   "declaration specifiers"));
1010438fd1498Szrj 	      else if (specs->typespec_word == cts_auto_type)
1010538fd1498Szrj 		error_at (loc,
1010638fd1498Szrj 			  ("both %<short%> and %<__auto_type%> in "
1010738fd1498Szrj 			   "declaration specifiers"));
1010838fd1498Szrj 	      else if (specs->typespec_word == cts_void)
1010938fd1498Szrj 		error_at (loc,
1011038fd1498Szrj 			  ("both %<short%> and %<void%> in "
1011138fd1498Szrj 			   "declaration specifiers"));
1011238fd1498Szrj 	      else if (specs->typespec_word == cts_int_n)
1011338fd1498Szrj 		error_at (loc,
1011438fd1498Szrj 			  ("both %<short%> and %<__int%d%> in "
1011538fd1498Szrj 			   "declaration specifiers"),
1011638fd1498Szrj 			  int_n_data[specs->int_n_idx].bitsize);
1011738fd1498Szrj 	      else if (specs->typespec_word == cts_bool)
1011838fd1498Szrj 		error_at (loc,
1011938fd1498Szrj 			  ("both %<short%> and %<_Bool%> in "
1012038fd1498Szrj 			   "declaration specifiers"));
1012138fd1498Szrj 	      else if (specs->typespec_word == cts_char)
1012238fd1498Szrj 		error_at (loc,
1012338fd1498Szrj 			  ("both %<short%> and %<char%> in "
1012438fd1498Szrj 			   "declaration specifiers"));
1012538fd1498Szrj 	      else if (specs->typespec_word == cts_float)
1012638fd1498Szrj 		error_at (loc,
1012738fd1498Szrj 			  ("both %<short%> and %<float%> in "
1012838fd1498Szrj 			   "declaration specifiers"));
1012938fd1498Szrj 	      else if (specs->typespec_word == cts_double)
1013038fd1498Szrj 		error_at (loc,
1013138fd1498Szrj 			  ("both %<short%> and %<double%> in "
1013238fd1498Szrj 			   "declaration specifiers"));
1013338fd1498Szrj 	      else if (specs->typespec_word == cts_floatn_nx)
1013438fd1498Szrj 		error_at (loc,
1013538fd1498Szrj 			  ("both %<short%> and %<_Float%d%s%> in "
1013638fd1498Szrj 			   "declaration specifiers"),
1013738fd1498Szrj 			  floatn_nx_types[specs->floatn_nx_idx].n,
1013838fd1498Szrj 			  (floatn_nx_types[specs->floatn_nx_idx].extended
1013938fd1498Szrj 			   ? "x"
1014038fd1498Szrj 			   : ""));
1014138fd1498Szrj 	      else if (specs->typespec_word == cts_dfloat32)
1014238fd1498Szrj                 error_at (loc,
1014338fd1498Szrj 			  ("both %<short%> and %<_Decimal32%> in "
1014438fd1498Szrj 			   "declaration specifiers"));
1014538fd1498Szrj 	      else if (specs->typespec_word == cts_dfloat64)
1014638fd1498Szrj 		error_at (loc,
1014738fd1498Szrj 			  ("both %<short%> and %<_Decimal64%> in "
1014838fd1498Szrj 			   "declaration specifiers"));
1014938fd1498Szrj 	      else if (specs->typespec_word == cts_dfloat128)
1015038fd1498Szrj 		error_at (loc,
1015138fd1498Szrj 			  ("both %<short%> and %<_Decimal128%> in "
1015238fd1498Szrj 			   "declaration specifiers"));
1015338fd1498Szrj 	      else
1015438fd1498Szrj 		{
1015538fd1498Szrj 		  specs->short_p = true;
1015638fd1498Szrj 		  specs->locations[cdw_short] = loc;
1015738fd1498Szrj 		}
1015838fd1498Szrj 	      break;
1015938fd1498Szrj 	    case RID_SIGNED:
1016038fd1498Szrj 	      dupe = specs->signed_p;
1016138fd1498Szrj 	      if (specs->unsigned_p)
1016238fd1498Szrj 		error_at (loc,
1016338fd1498Szrj 			  ("both %<signed%> and %<unsigned%> in "
1016438fd1498Szrj 			   "declaration specifiers"));
1016538fd1498Szrj 	      else if (specs->typespec_word == cts_auto_type)
1016638fd1498Szrj 		error_at (loc,
1016738fd1498Szrj 			  ("both %<signed%> and %<__auto_type%> in "
1016838fd1498Szrj 			   "declaration specifiers"));
1016938fd1498Szrj 	      else if (specs->typespec_word == cts_void)
1017038fd1498Szrj 		error_at (loc,
1017138fd1498Szrj 			  ("both %<signed%> and %<void%> in "
1017238fd1498Szrj 			   "declaration specifiers"));
1017338fd1498Szrj 	      else if (specs->typespec_word == cts_bool)
1017438fd1498Szrj 		error_at (loc,
1017538fd1498Szrj 			  ("both %<signed%> and %<_Bool%> in "
1017638fd1498Szrj 			   "declaration specifiers"));
1017738fd1498Szrj 	      else if (specs->typespec_word == cts_float)
1017838fd1498Szrj 		error_at (loc,
1017938fd1498Szrj 			  ("both %<signed%> and %<float%> in "
1018038fd1498Szrj 			   "declaration specifiers"));
1018138fd1498Szrj 	      else if (specs->typespec_word == cts_double)
1018238fd1498Szrj 		error_at (loc,
1018338fd1498Szrj 			  ("both %<signed%> and %<double%> in "
1018438fd1498Szrj 			   "declaration specifiers"));
1018538fd1498Szrj 	      else if (specs->typespec_word == cts_floatn_nx)
1018638fd1498Szrj 		error_at (loc,
1018738fd1498Szrj 			  ("both %<signed%> and %<_Float%d%s%> in "
1018838fd1498Szrj 			   "declaration specifiers"),
1018938fd1498Szrj 			  floatn_nx_types[specs->floatn_nx_idx].n,
1019038fd1498Szrj 			  (floatn_nx_types[specs->floatn_nx_idx].extended
1019138fd1498Szrj 			   ? "x"
1019238fd1498Szrj 			   : ""));
1019338fd1498Szrj 	      else if (specs->typespec_word == cts_dfloat32)
1019438fd1498Szrj 		error_at (loc,
1019538fd1498Szrj 			  ("both %<signed%> and %<_Decimal32%> in "
1019638fd1498Szrj 			   "declaration specifiers"));
1019738fd1498Szrj 	      else if (specs->typespec_word == cts_dfloat64)
1019838fd1498Szrj 		error_at (loc,
1019938fd1498Szrj 			  ("both %<signed%> and %<_Decimal64%> in "
1020038fd1498Szrj 			   "declaration specifiers"));
1020138fd1498Szrj 	      else if (specs->typespec_word == cts_dfloat128)
1020238fd1498Szrj 		error_at (loc,
1020338fd1498Szrj 			  ("both %<signed%> and %<_Decimal128%> in "
1020438fd1498Szrj 			   "declaration specifiers"));
1020538fd1498Szrj 	      else
1020638fd1498Szrj 		{
1020738fd1498Szrj 		  specs->signed_p = true;
1020838fd1498Szrj 		  specs->locations[cdw_signed] = loc;
1020938fd1498Szrj 		}
1021038fd1498Szrj 	      break;
1021138fd1498Szrj 	    case RID_UNSIGNED:
1021238fd1498Szrj 	      dupe = specs->unsigned_p;
1021338fd1498Szrj 	      if (specs->signed_p)
1021438fd1498Szrj 		error_at (loc,
1021538fd1498Szrj 			  ("both %<signed%> and %<unsigned%> in "
1021638fd1498Szrj 			   "declaration specifiers"));
1021738fd1498Szrj 	      else if (specs->typespec_word == cts_auto_type)
1021838fd1498Szrj 		error_at (loc,
1021938fd1498Szrj 			  ("both %<unsigned%> and %<__auto_type%> in "
1022038fd1498Szrj 			   "declaration specifiers"));
1022138fd1498Szrj 	      else if (specs->typespec_word == cts_void)
1022238fd1498Szrj 		error_at (loc,
1022338fd1498Szrj 			  ("both %<unsigned%> and %<void%> in "
1022438fd1498Szrj 			   "declaration specifiers"));
1022538fd1498Szrj 	      else if (specs->typespec_word == cts_bool)
1022638fd1498Szrj 		error_at (loc,
1022738fd1498Szrj 			  ("both %<unsigned%> and %<_Bool%> in "
1022838fd1498Szrj 			   "declaration specifiers"));
1022938fd1498Szrj 	      else if (specs->typespec_word == cts_float)
1023038fd1498Szrj 		error_at (loc,
1023138fd1498Szrj 			  ("both %<unsigned%> and %<float%> in "
1023238fd1498Szrj 			   "declaration specifiers"));
1023338fd1498Szrj 	      else if (specs->typespec_word == cts_double)
1023438fd1498Szrj 		error_at (loc,
1023538fd1498Szrj 			  ("both %<unsigned%> and %<double%> in "
1023638fd1498Szrj 			   "declaration specifiers"));
1023738fd1498Szrj 	      else if (specs->typespec_word == cts_floatn_nx)
1023838fd1498Szrj 		error_at (loc,
1023938fd1498Szrj 			  ("both %<unsigned%> and %<_Float%d%s%> in "
1024038fd1498Szrj 			   "declaration specifiers"),
1024138fd1498Szrj 			  floatn_nx_types[specs->floatn_nx_idx].n,
1024238fd1498Szrj 			  (floatn_nx_types[specs->floatn_nx_idx].extended
1024338fd1498Szrj 			   ? "x"
1024438fd1498Szrj 			   : ""));
1024538fd1498Szrj               else if (specs->typespec_word == cts_dfloat32)
1024638fd1498Szrj 		error_at (loc,
1024738fd1498Szrj 			  ("both %<unsigned%> and %<_Decimal32%> in "
1024838fd1498Szrj 			   "declaration specifiers"));
1024938fd1498Szrj 	      else if (specs->typespec_word == cts_dfloat64)
1025038fd1498Szrj 		error_at (loc,
1025138fd1498Szrj 			  ("both %<unsigned%> and %<_Decimal64%> in "
1025238fd1498Szrj 			   "declaration specifiers"));
1025338fd1498Szrj 	      else if (specs->typespec_word == cts_dfloat128)
1025438fd1498Szrj 		error_at (loc,
1025538fd1498Szrj 			  ("both %<unsigned%> and %<_Decimal128%> in "
1025638fd1498Szrj 			   "declaration specifiers"));
1025738fd1498Szrj 	      else
1025838fd1498Szrj 		{
1025938fd1498Szrj 		  specs->unsigned_p = true;
1026038fd1498Szrj 		  specs->locations[cdw_unsigned] = loc;
1026138fd1498Szrj 		}
1026238fd1498Szrj 	      break;
1026338fd1498Szrj 	    case RID_COMPLEX:
1026438fd1498Szrj 	      dupe = specs->complex_p;
1026538fd1498Szrj 	      if (!in_system_header_at (loc))
1026638fd1498Szrj 		pedwarn_c90 (loc, OPT_Wpedantic,
1026738fd1498Szrj 			     "ISO C90 does not support complex types");
1026838fd1498Szrj 	      if (specs->typespec_word == cts_auto_type)
1026938fd1498Szrj 		error_at (loc,
1027038fd1498Szrj 			  ("both %<complex%> and %<__auto_type%> in "
1027138fd1498Szrj 			   "declaration specifiers"));
1027238fd1498Szrj 	      else if (specs->typespec_word == cts_void)
1027338fd1498Szrj 		error_at (loc,
1027438fd1498Szrj 			  ("both %<complex%> and %<void%> in "
1027538fd1498Szrj 			   "declaration specifiers"));
1027638fd1498Szrj 	      else if (specs->typespec_word == cts_bool)
1027738fd1498Szrj 		error_at (loc,
1027838fd1498Szrj 			  ("both %<complex%> and %<_Bool%> in "
1027938fd1498Szrj 			   "declaration specifiers"));
1028038fd1498Szrj               else if (specs->typespec_word == cts_dfloat32)
1028138fd1498Szrj 		error_at (loc,
1028238fd1498Szrj 			  ("both %<complex%> and %<_Decimal32%> in "
1028338fd1498Szrj 			   "declaration specifiers"));
1028438fd1498Szrj 	      else if (specs->typespec_word == cts_dfloat64)
1028538fd1498Szrj 		error_at (loc,
1028638fd1498Szrj 			  ("both %<complex%> and %<_Decimal64%> in "
1028738fd1498Szrj 			   "declaration specifiers"));
1028838fd1498Szrj 	      else if (specs->typespec_word == cts_dfloat128)
1028938fd1498Szrj 		error_at (loc,
1029038fd1498Szrj 			  ("both %<complex%> and %<_Decimal128%> in "
1029138fd1498Szrj 			   "declaration specifiers"));
1029238fd1498Szrj 	      else if (specs->typespec_word == cts_fract)
1029338fd1498Szrj 		error_at (loc,
1029438fd1498Szrj 			  ("both %<complex%> and %<_Fract%> in "
1029538fd1498Szrj 			   "declaration specifiers"));
1029638fd1498Szrj 	      else if (specs->typespec_word == cts_accum)
1029738fd1498Szrj 		error_at (loc,
1029838fd1498Szrj 			  ("both %<complex%> and %<_Accum%> in "
1029938fd1498Szrj 			   "declaration specifiers"));
1030038fd1498Szrj 	      else if (specs->saturating_p)
1030138fd1498Szrj 		error_at (loc,
1030238fd1498Szrj 			  ("both %<complex%> and %<_Sat%> in "
1030338fd1498Szrj 			   "declaration specifiers"));
1030438fd1498Szrj 	      else
1030538fd1498Szrj 		{
1030638fd1498Szrj 		  specs->complex_p = true;
1030738fd1498Szrj 		  specs->locations[cdw_complex] = loc;
1030838fd1498Szrj 		}
1030938fd1498Szrj 	      break;
1031038fd1498Szrj 	    case RID_SAT:
1031138fd1498Szrj 	      dupe = specs->saturating_p;
1031238fd1498Szrj 	      pedwarn (loc, OPT_Wpedantic,
1031338fd1498Szrj 		       "ISO C does not support saturating types");
1031438fd1498Szrj 	      if (specs->typespec_word == cts_int_n)
1031538fd1498Szrj 	        {
1031638fd1498Szrj 		  error_at (loc,
1031738fd1498Szrj 			    ("both %<_Sat%> and %<__int%d%> in "
1031838fd1498Szrj 			     "declaration specifiers"),
1031938fd1498Szrj 			    int_n_data[specs->int_n_idx].bitsize);
1032038fd1498Szrj 	        }
1032138fd1498Szrj 	      else if (specs->typespec_word == cts_auto_type)
1032238fd1498Szrj 		error_at (loc,
1032338fd1498Szrj 			  ("both %<_Sat%> and %<__auto_type%> in "
1032438fd1498Szrj 			   "declaration specifiers"));
1032538fd1498Szrj 	      else if (specs->typespec_word == cts_void)
1032638fd1498Szrj 		error_at (loc,
1032738fd1498Szrj 			  ("both %<_Sat%> and %<void%> in "
1032838fd1498Szrj 			   "declaration specifiers"));
1032938fd1498Szrj 	      else if (specs->typespec_word == cts_bool)
1033038fd1498Szrj 		error_at (loc,
1033138fd1498Szrj 			  ("both %<_Sat%> and %<_Bool%> in "
1033238fd1498Szrj 			   "declaration specifiers"));
1033338fd1498Szrj 	      else if (specs->typespec_word == cts_char)
1033438fd1498Szrj 		error_at (loc,
1033538fd1498Szrj 			  ("both %<_Sat%> and %<char%> in "
1033638fd1498Szrj 			   "declaration specifiers"));
1033738fd1498Szrj 	      else if (specs->typespec_word == cts_int)
1033838fd1498Szrj 		error_at (loc,
1033938fd1498Szrj 			  ("both %<_Sat%> and %<int%> in "
1034038fd1498Szrj 			   "declaration specifiers"));
1034138fd1498Szrj 	      else if (specs->typespec_word == cts_float)
1034238fd1498Szrj 		error_at (loc,
1034338fd1498Szrj 			  ("both %<_Sat%> and %<float%> in "
1034438fd1498Szrj 			   "declaration specifiers"));
1034538fd1498Szrj 	      else if (specs->typespec_word == cts_double)
1034638fd1498Szrj 		error_at (loc,
1034738fd1498Szrj 			  ("both %<_Sat%> and %<double%> in "
1034838fd1498Szrj 			   "declaration specifiers"));
1034938fd1498Szrj 	      else if (specs->typespec_word == cts_floatn_nx)
1035038fd1498Szrj 		error_at (loc,
1035138fd1498Szrj 			  ("both %<_Sat%> and %<_Float%d%s%> in "
1035238fd1498Szrj 			   "declaration specifiers"),
1035338fd1498Szrj 			  floatn_nx_types[specs->floatn_nx_idx].n,
1035438fd1498Szrj 			  (floatn_nx_types[specs->floatn_nx_idx].extended
1035538fd1498Szrj 			   ? "x"
1035638fd1498Szrj 			   : ""));
1035738fd1498Szrj               else if (specs->typespec_word == cts_dfloat32)
1035838fd1498Szrj 		error_at (loc,
1035938fd1498Szrj 			  ("both %<_Sat%> and %<_Decimal32%> in "
1036038fd1498Szrj 			   "declaration specifiers"));
1036138fd1498Szrj 	      else if (specs->typespec_word == cts_dfloat64)
1036238fd1498Szrj 		error_at (loc,
1036338fd1498Szrj 			  ("both %<_Sat%> and %<_Decimal64%> in "
1036438fd1498Szrj 			   "declaration specifiers"));
1036538fd1498Szrj 	      else if (specs->typespec_word == cts_dfloat128)
1036638fd1498Szrj 		error_at (loc,
1036738fd1498Szrj 			  ("both %<_Sat%> and %<_Decimal128%> in "
1036838fd1498Szrj 			   "declaration specifiers"));
1036938fd1498Szrj 	      else if (specs->complex_p)
1037038fd1498Szrj 		error_at (loc,
1037138fd1498Szrj 			  ("both %<_Sat%> and %<complex%> in "
1037238fd1498Szrj 			   "declaration specifiers"));
1037338fd1498Szrj 	      else
1037438fd1498Szrj 		{
1037538fd1498Szrj 		  specs->saturating_p = true;
1037638fd1498Szrj 		  specs->locations[cdw_saturating] = loc;
1037738fd1498Szrj 		}
1037838fd1498Szrj 	      break;
1037938fd1498Szrj 	    default:
1038038fd1498Szrj 	      gcc_unreachable ();
1038138fd1498Szrj 	    }
1038238fd1498Szrj 
1038338fd1498Szrj 	  if (dupe)
1038438fd1498Szrj 	    error_at (loc, "duplicate %qE", type);
1038538fd1498Szrj 
1038638fd1498Szrj 	  return specs;
1038738fd1498Szrj 	}
1038838fd1498Szrj       else
1038938fd1498Szrj 	{
1039038fd1498Szrj 	  /* "void", "_Bool", "char", "int", "float", "double",
1039138fd1498Szrj 	     "_FloatN", "_FloatNx", "_Decimal32", "__intN",
1039238fd1498Szrj 	     "_Decimal64", "_Decimal128", "_Fract", "_Accum" or
1039338fd1498Szrj 	     "__auto_type".  */
1039438fd1498Szrj 	  if (specs->typespec_word != cts_none)
1039538fd1498Szrj 	    {
1039638fd1498Szrj 	      error_at (loc,
1039738fd1498Szrj 			"two or more data types in declaration specifiers");
1039838fd1498Szrj 	      return specs;
1039938fd1498Szrj 	    }
1040038fd1498Szrj 	  switch (i)
1040138fd1498Szrj 	    {
1040238fd1498Szrj 	    case RID_AUTO_TYPE:
1040338fd1498Szrj 	      if (specs->long_p)
1040438fd1498Szrj 		error_at (loc,
1040538fd1498Szrj 			  ("both %<long%> and %<__auto_type%> in "
1040638fd1498Szrj 			   "declaration specifiers"));
1040738fd1498Szrj 	      else if (specs->short_p)
1040838fd1498Szrj 		error_at (loc,
1040938fd1498Szrj 			  ("both %<short%> and %<__auto_type%> in "
1041038fd1498Szrj 			   "declaration specifiers"));
1041138fd1498Szrj 	      else if (specs->signed_p)
1041238fd1498Szrj 		error_at (loc,
1041338fd1498Szrj 			  ("both %<signed%> and %<__auto_type%> in "
1041438fd1498Szrj 			   "declaration specifiers"));
1041538fd1498Szrj 	      else if (specs->unsigned_p)
1041638fd1498Szrj 		error_at (loc,
1041738fd1498Szrj 			  ("both %<unsigned%> and %<__auto_type%> in "
1041838fd1498Szrj 			   "declaration specifiers"));
1041938fd1498Szrj 	      else if (specs->complex_p)
1042038fd1498Szrj 		error_at (loc,
1042138fd1498Szrj 			  ("both %<complex%> and %<__auto_type%> in "
1042238fd1498Szrj 			   "declaration specifiers"));
1042338fd1498Szrj 	      else if (specs->saturating_p)
1042438fd1498Szrj 		error_at (loc,
1042538fd1498Szrj 			  ("both %<_Sat%> and %<__auto_type%> in "
1042638fd1498Szrj 			   "declaration specifiers"));
1042738fd1498Szrj 	      else
1042838fd1498Szrj 		{
1042938fd1498Szrj 		  specs->typespec_word = cts_auto_type;
1043038fd1498Szrj 		  specs->locations[cdw_typespec] = loc;
1043138fd1498Szrj 		}
1043238fd1498Szrj 	      return specs;
1043338fd1498Szrj 	    case RID_INT_N_0:
1043438fd1498Szrj 	    case RID_INT_N_1:
1043538fd1498Szrj 	    case RID_INT_N_2:
1043638fd1498Szrj 	    case RID_INT_N_3:
1043738fd1498Szrj 	      specs->int_n_idx = i - RID_INT_N_0;
1043838fd1498Szrj 	      if (!in_system_header_at (input_location))
1043938fd1498Szrj 		pedwarn (loc, OPT_Wpedantic,
1044038fd1498Szrj 			 "ISO C does not support %<__int%d%> types",
1044138fd1498Szrj 			 int_n_data[specs->int_n_idx].bitsize);
1044238fd1498Szrj 
1044338fd1498Szrj 	      if (specs->long_p)
1044438fd1498Szrj 		error_at (loc,
1044538fd1498Szrj 			  ("both %<__int%d%> and %<long%> in "
1044638fd1498Szrj 			   "declaration specifiers"),
1044738fd1498Szrj 			  int_n_data[specs->int_n_idx].bitsize);
1044838fd1498Szrj 	      else if (specs->saturating_p)
1044938fd1498Szrj 		error_at (loc,
1045038fd1498Szrj 			  ("both %<_Sat%> and %<__int%d%> in "
1045138fd1498Szrj 			   "declaration specifiers"),
1045238fd1498Szrj 			  int_n_data[specs->int_n_idx].bitsize);
1045338fd1498Szrj 	      else if (specs->short_p)
1045438fd1498Szrj 		error_at (loc,
1045538fd1498Szrj 			  ("both %<__int%d%> and %<short%> in "
1045638fd1498Szrj 			   "declaration specifiers"),
1045738fd1498Szrj 			  int_n_data[specs->int_n_idx].bitsize);
1045838fd1498Szrj 	      else if (! int_n_enabled_p[specs->int_n_idx])
1045938fd1498Szrj 		{
1046038fd1498Szrj 		  specs->typespec_word = cts_int_n;
1046138fd1498Szrj 		  error_at (loc,
1046238fd1498Szrj 			    "%<__int%d%> is not supported on this target",
1046338fd1498Szrj 			    int_n_data[specs->int_n_idx].bitsize);
1046438fd1498Szrj 		}
1046538fd1498Szrj 	      else
1046638fd1498Szrj 		{
1046738fd1498Szrj 		  specs->typespec_word = cts_int_n;
1046838fd1498Szrj 		  specs->locations[cdw_typespec] = loc;
1046938fd1498Szrj 		}
1047038fd1498Szrj 	      return specs;
1047138fd1498Szrj 	    case RID_VOID:
1047238fd1498Szrj 	      if (specs->long_p)
1047338fd1498Szrj 		error_at (loc,
1047438fd1498Szrj 			  ("both %<long%> and %<void%> in "
1047538fd1498Szrj 			   "declaration specifiers"));
1047638fd1498Szrj 	      else if (specs->short_p)
1047738fd1498Szrj 		error_at (loc,
1047838fd1498Szrj 			  ("both %<short%> and %<void%> in "
1047938fd1498Szrj 			   "declaration specifiers"));
1048038fd1498Szrj 	      else if (specs->signed_p)
1048138fd1498Szrj 		error_at (loc,
1048238fd1498Szrj 			  ("both %<signed%> and %<void%> in "
1048338fd1498Szrj 			   "declaration specifiers"));
1048438fd1498Szrj 	      else if (specs->unsigned_p)
1048538fd1498Szrj 		error_at (loc,
1048638fd1498Szrj 			  ("both %<unsigned%> and %<void%> in "
1048738fd1498Szrj 			   "declaration specifiers"));
1048838fd1498Szrj 	      else if (specs->complex_p)
1048938fd1498Szrj 		error_at (loc,
1049038fd1498Szrj 			  ("both %<complex%> and %<void%> in "
1049138fd1498Szrj 			   "declaration specifiers"));
1049238fd1498Szrj 	      else if (specs->saturating_p)
1049338fd1498Szrj 		error_at (loc,
1049438fd1498Szrj 			  ("both %<_Sat%> and %<void%> in "
1049538fd1498Szrj 			   "declaration specifiers"));
1049638fd1498Szrj 	      else
1049738fd1498Szrj 		{
1049838fd1498Szrj 		  specs->typespec_word = cts_void;
1049938fd1498Szrj 		  specs->locations[cdw_typespec] = loc;
1050038fd1498Szrj 		}
1050138fd1498Szrj 	      return specs;
1050238fd1498Szrj 	    case RID_BOOL:
1050338fd1498Szrj 	      if (!in_system_header_at (loc))
1050438fd1498Szrj 		pedwarn_c90 (loc, OPT_Wpedantic,
1050538fd1498Szrj 			     "ISO C90 does not support boolean types");
1050638fd1498Szrj 	      if (specs->long_p)
1050738fd1498Szrj 		error_at (loc,
1050838fd1498Szrj 			  ("both %<long%> and %<_Bool%> in "
1050938fd1498Szrj 			   "declaration specifiers"));
1051038fd1498Szrj 	      else if (specs->short_p)
1051138fd1498Szrj 		error_at (loc,
1051238fd1498Szrj 			  ("both %<short%> and %<_Bool%> in "
1051338fd1498Szrj 			   "declaration specifiers"));
1051438fd1498Szrj 	      else if (specs->signed_p)
1051538fd1498Szrj 		error_at (loc,
1051638fd1498Szrj 			  ("both %<signed%> and %<_Bool%> in "
1051738fd1498Szrj 			   "declaration specifiers"));
1051838fd1498Szrj 	      else if (specs->unsigned_p)
1051938fd1498Szrj 		error_at (loc,
1052038fd1498Szrj 			  ("both %<unsigned%> and %<_Bool%> in "
1052138fd1498Szrj 			   "declaration specifiers"));
1052238fd1498Szrj 	      else if (specs->complex_p)
1052338fd1498Szrj 		error_at (loc,
1052438fd1498Szrj 			  ("both %<complex%> and %<_Bool%> in "
1052538fd1498Szrj 			   "declaration specifiers"));
1052638fd1498Szrj 	      else if (specs->saturating_p)
1052738fd1498Szrj 		error_at (loc,
1052838fd1498Szrj 			  ("both %<_Sat%> and %<_Bool%> in "
1052938fd1498Szrj 			   "declaration specifiers"));
1053038fd1498Szrj 	      else
1053138fd1498Szrj 		{
1053238fd1498Szrj 		  specs->typespec_word = cts_bool;
1053338fd1498Szrj 		  specs->locations[cdw_typespec] = loc;
1053438fd1498Szrj 		}
1053538fd1498Szrj 	      return specs;
1053638fd1498Szrj 	    case RID_CHAR:
1053738fd1498Szrj 	      if (specs->long_p)
1053838fd1498Szrj 		error_at (loc,
1053938fd1498Szrj 			  ("both %<long%> and %<char%> in "
1054038fd1498Szrj 			   "declaration specifiers"));
1054138fd1498Szrj 	      else if (specs->short_p)
1054238fd1498Szrj 		error_at (loc,
1054338fd1498Szrj 			  ("both %<short%> and %<char%> in "
1054438fd1498Szrj 			   "declaration specifiers"));
1054538fd1498Szrj 	      else if (specs->saturating_p)
1054638fd1498Szrj 		error_at (loc,
1054738fd1498Szrj 			  ("both %<_Sat%> and %<char%> in "
1054838fd1498Szrj 			   "declaration specifiers"));
1054938fd1498Szrj 	      else
1055038fd1498Szrj 		{
1055138fd1498Szrj 		  specs->typespec_word = cts_char;
1055238fd1498Szrj 		  specs->locations[cdw_typespec] = loc;
1055338fd1498Szrj 		}
1055438fd1498Szrj 	      return specs;
1055538fd1498Szrj 	    case RID_INT:
1055638fd1498Szrj 	      if (specs->saturating_p)
1055738fd1498Szrj 		error_at (loc,
1055838fd1498Szrj 			  ("both %<_Sat%> and %<int%> in "
1055938fd1498Szrj 			   "declaration specifiers"));
1056038fd1498Szrj 	      else
1056138fd1498Szrj 		{
1056238fd1498Szrj 		  specs->typespec_word = cts_int;
1056338fd1498Szrj 		  specs->locations[cdw_typespec] = loc;
1056438fd1498Szrj 		}
1056538fd1498Szrj 	      return specs;
1056638fd1498Szrj 	    case RID_FLOAT:
1056738fd1498Szrj 	      if (specs->long_p)
1056838fd1498Szrj 		error_at (loc,
1056938fd1498Szrj 			  ("both %<long%> and %<float%> in "
1057038fd1498Szrj 			   "declaration specifiers"));
1057138fd1498Szrj 	      else if (specs->short_p)
1057238fd1498Szrj 		error_at (loc,
1057338fd1498Szrj 			  ("both %<short%> and %<float%> in "
1057438fd1498Szrj 			   "declaration specifiers"));
1057538fd1498Szrj 	      else if (specs->signed_p)
1057638fd1498Szrj 		error_at (loc,
1057738fd1498Szrj 			  ("both %<signed%> and %<float%> in "
1057838fd1498Szrj 			   "declaration specifiers"));
1057938fd1498Szrj 	      else if (specs->unsigned_p)
1058038fd1498Szrj 		error_at (loc,
1058138fd1498Szrj 			  ("both %<unsigned%> and %<float%> in "
1058238fd1498Szrj 			   "declaration specifiers"));
1058338fd1498Szrj 	      else if (specs->saturating_p)
1058438fd1498Szrj 		error_at (loc,
1058538fd1498Szrj 			  ("both %<_Sat%> and %<float%> in "
1058638fd1498Szrj 			   "declaration specifiers"));
1058738fd1498Szrj 	      else
1058838fd1498Szrj 		{
1058938fd1498Szrj 		  specs->typespec_word = cts_float;
1059038fd1498Szrj 		  specs->locations[cdw_typespec] = loc;
1059138fd1498Szrj 		}
1059238fd1498Szrj 	      return specs;
1059338fd1498Szrj 	    case RID_DOUBLE:
1059438fd1498Szrj 	      if (specs->long_long_p)
1059538fd1498Szrj 		error_at (loc,
1059638fd1498Szrj 			  ("both %<long long%> and %<double%> in "
1059738fd1498Szrj 			   "declaration specifiers"));
1059838fd1498Szrj 	      else if (specs->short_p)
1059938fd1498Szrj 		error_at (loc,
1060038fd1498Szrj 			  ("both %<short%> and %<double%> in "
1060138fd1498Szrj 			   "declaration specifiers"));
1060238fd1498Szrj 	      else if (specs->signed_p)
1060338fd1498Szrj 		error_at (loc,
1060438fd1498Szrj 			  ("both %<signed%> and %<double%> in "
1060538fd1498Szrj 			   "declaration specifiers"));
1060638fd1498Szrj 	      else if (specs->unsigned_p)
1060738fd1498Szrj 		error_at (loc,
1060838fd1498Szrj 			  ("both %<unsigned%> and %<double%> in "
1060938fd1498Szrj 			   "declaration specifiers"));
1061038fd1498Szrj 	      else if (specs->saturating_p)
1061138fd1498Szrj 		error_at (loc,
1061238fd1498Szrj 			  ("both %<_Sat%> and %<double%> in "
1061338fd1498Szrj 			   "declaration specifiers"));
1061438fd1498Szrj 	      else
1061538fd1498Szrj 		{
1061638fd1498Szrj 		  specs->typespec_word = cts_double;
1061738fd1498Szrj 		  specs->locations[cdw_typespec] = loc;
1061838fd1498Szrj 		}
1061938fd1498Szrj 	      return specs;
1062038fd1498Szrj 	    CASE_RID_FLOATN_NX:
1062138fd1498Szrj 	      specs->floatn_nx_idx = i - RID_FLOATN_NX_FIRST;
1062238fd1498Szrj 	      if (!in_system_header_at (input_location))
1062338fd1498Szrj 		pedwarn (loc, OPT_Wpedantic,
1062438fd1498Szrj 			 "ISO C does not support the %<_Float%d%s%> type",
1062538fd1498Szrj 			 floatn_nx_types[specs->floatn_nx_idx].n,
1062638fd1498Szrj 			 (floatn_nx_types[specs->floatn_nx_idx].extended
1062738fd1498Szrj 			  ? "x"
1062838fd1498Szrj 			  : ""));
1062938fd1498Szrj 
1063038fd1498Szrj 	      if (specs->long_p)
1063138fd1498Szrj 		error_at (loc,
1063238fd1498Szrj 			  ("both %<long%> and %<_Float%d%s%> in "
1063338fd1498Szrj 			   "declaration specifiers"),
1063438fd1498Szrj 			  floatn_nx_types[specs->floatn_nx_idx].n,
1063538fd1498Szrj 			  (floatn_nx_types[specs->floatn_nx_idx].extended
1063638fd1498Szrj 			   ? "x"
1063738fd1498Szrj 			   : ""));
1063838fd1498Szrj 	      else if (specs->short_p)
1063938fd1498Szrj 		error_at (loc,
1064038fd1498Szrj 			  ("both %<short%> and %<_Float%d%s%> in "
1064138fd1498Szrj 			   "declaration specifiers"),
1064238fd1498Szrj 			  floatn_nx_types[specs->floatn_nx_idx].n,
1064338fd1498Szrj 			  (floatn_nx_types[specs->floatn_nx_idx].extended
1064438fd1498Szrj 			   ? "x"
1064538fd1498Szrj 			   : ""));
1064638fd1498Szrj 	      else if (specs->signed_p)
1064738fd1498Szrj 		error_at (loc,
1064838fd1498Szrj 			  ("both %<signed%> and %<_Float%d%s%> in "
1064938fd1498Szrj 			   "declaration specifiers"),
1065038fd1498Szrj 			  floatn_nx_types[specs->floatn_nx_idx].n,
1065138fd1498Szrj 			  (floatn_nx_types[specs->floatn_nx_idx].extended
1065238fd1498Szrj 			   ? "x"
1065338fd1498Szrj 			   : ""));
1065438fd1498Szrj 	      else if (specs->unsigned_p)
1065538fd1498Szrj 		error_at (loc,
1065638fd1498Szrj 			  ("both %<unsigned%> and %<_Float%d%s%> in "
1065738fd1498Szrj 			   "declaration specifiers"),
1065838fd1498Szrj 			  floatn_nx_types[specs->floatn_nx_idx].n,
1065938fd1498Szrj 			  (floatn_nx_types[specs->floatn_nx_idx].extended
1066038fd1498Szrj 			   ? "x"
1066138fd1498Szrj 			   : ""));
1066238fd1498Szrj 	      else if (specs->saturating_p)
1066338fd1498Szrj 		error_at (loc,
1066438fd1498Szrj 			  ("both %<_Sat%> and %<_Float%d%s%> in "
1066538fd1498Szrj 			   "declaration specifiers"),
1066638fd1498Szrj 			  floatn_nx_types[specs->floatn_nx_idx].n,
1066738fd1498Szrj 			  (floatn_nx_types[specs->floatn_nx_idx].extended
1066838fd1498Szrj 			   ? "x"
1066938fd1498Szrj 			   : ""));
1067038fd1498Szrj 	      else if (FLOATN_NX_TYPE_NODE (specs->floatn_nx_idx) == NULL_TREE)
1067138fd1498Szrj 		{
1067238fd1498Szrj 		  specs->typespec_word = cts_floatn_nx;
1067338fd1498Szrj 		  error_at (loc,
1067438fd1498Szrj 			    "%<_Float%d%s%> is not supported on this target",
1067538fd1498Szrj 			    floatn_nx_types[specs->floatn_nx_idx].n,
1067638fd1498Szrj 			    (floatn_nx_types[specs->floatn_nx_idx].extended
1067738fd1498Szrj 			     ? "x"
1067838fd1498Szrj 			     : ""));
1067938fd1498Szrj 		}
1068038fd1498Szrj 	      else
1068138fd1498Szrj 		{
1068238fd1498Szrj 		  specs->typespec_word = cts_floatn_nx;
1068338fd1498Szrj 		  specs->locations[cdw_typespec] = loc;
1068438fd1498Szrj 		}
1068538fd1498Szrj 	      return specs;
1068638fd1498Szrj 	    case RID_DFLOAT32:
1068738fd1498Szrj 	    case RID_DFLOAT64:
1068838fd1498Szrj 	    case RID_DFLOAT128:
1068938fd1498Szrj 	      {
1069038fd1498Szrj 		const char *str;
1069138fd1498Szrj 		if (i == RID_DFLOAT32)
1069238fd1498Szrj 		  str = "_Decimal32";
1069338fd1498Szrj 		else if (i == RID_DFLOAT64)
1069438fd1498Szrj 		  str = "_Decimal64";
1069538fd1498Szrj 		else
1069638fd1498Szrj 		  str = "_Decimal128";
1069738fd1498Szrj 		if (specs->long_long_p)
1069838fd1498Szrj 		  error_at (loc,
1069938fd1498Szrj 			    ("both %<long long%> and %qs in "
1070038fd1498Szrj 			     "declaration specifiers"),
1070138fd1498Szrj 			    str);
1070238fd1498Szrj 		if (specs->long_p)
1070338fd1498Szrj 		  error_at (loc,
1070438fd1498Szrj 			    ("both %<long%> and %qs in "
1070538fd1498Szrj 			     "declaration specifiers"),
1070638fd1498Szrj 			    str);
1070738fd1498Szrj 		else if (specs->short_p)
1070838fd1498Szrj 		  error_at (loc,
1070938fd1498Szrj 			    ("both %<short%> and %qs in "
1071038fd1498Szrj 			     "declaration specifiers"),
1071138fd1498Szrj 			    str);
1071238fd1498Szrj 		else if (specs->signed_p)
1071338fd1498Szrj 		  error_at (loc,
1071438fd1498Szrj 			    ("both %<signed%> and %qs in "
1071538fd1498Szrj 			     "declaration specifiers"),
1071638fd1498Szrj 			    str);
1071738fd1498Szrj 		else if (specs->unsigned_p)
1071838fd1498Szrj 		  error_at (loc,
1071938fd1498Szrj 			    ("both %<unsigned%> and %qs in "
1072038fd1498Szrj 			     "declaration specifiers"),
1072138fd1498Szrj 			    str);
1072238fd1498Szrj                 else if (specs->complex_p)
1072338fd1498Szrj                   error_at (loc,
1072438fd1498Szrj 			    ("both %<complex%> and %qs in "
1072538fd1498Szrj 			     "declaration specifiers"),
1072638fd1498Szrj 			    str);
1072738fd1498Szrj                 else if (specs->saturating_p)
1072838fd1498Szrj                   error_at (loc,
1072938fd1498Szrj 			    ("both %<_Sat%> and %qs in "
1073038fd1498Szrj 			     "declaration specifiers"),
1073138fd1498Szrj 			    str);
1073238fd1498Szrj 		else if (i == RID_DFLOAT32)
1073338fd1498Szrj 		  specs->typespec_word = cts_dfloat32;
1073438fd1498Szrj 		else if (i == RID_DFLOAT64)
1073538fd1498Szrj 		  specs->typespec_word = cts_dfloat64;
1073638fd1498Szrj 		else
1073738fd1498Szrj 		  specs->typespec_word = cts_dfloat128;
1073838fd1498Szrj 		specs->locations[cdw_typespec] = loc;
1073938fd1498Szrj 	      }
1074038fd1498Szrj 	      if (!targetm.decimal_float_supported_p ())
1074138fd1498Szrj 		error_at (loc,
1074238fd1498Szrj 			  ("decimal floating point not supported "
1074338fd1498Szrj 			   "for this target"));
1074438fd1498Szrj 	      pedwarn (loc, OPT_Wpedantic,
1074538fd1498Szrj 		       "ISO C does not support decimal floating point");
1074638fd1498Szrj 	      return specs;
1074738fd1498Szrj 	    case RID_FRACT:
1074838fd1498Szrj 	    case RID_ACCUM:
1074938fd1498Szrj 	      {
1075038fd1498Szrj 		const char *str;
1075138fd1498Szrj 		if (i == RID_FRACT)
1075238fd1498Szrj 		  str = "_Fract";
1075338fd1498Szrj 		else
1075438fd1498Szrj 		  str = "_Accum";
1075538fd1498Szrj                 if (specs->complex_p)
1075638fd1498Szrj                   error_at (loc,
1075738fd1498Szrj 			    ("both %<complex%> and %qs in "
1075838fd1498Szrj 			     "declaration specifiers"),
1075938fd1498Szrj 			    str);
1076038fd1498Szrj 		else if (i == RID_FRACT)
1076138fd1498Szrj 		    specs->typespec_word = cts_fract;
1076238fd1498Szrj 		else
1076338fd1498Szrj 		    specs->typespec_word = cts_accum;
1076438fd1498Szrj 		specs->locations[cdw_typespec] = loc;
1076538fd1498Szrj 	      }
1076638fd1498Szrj 	      if (!targetm.fixed_point_supported_p ())
1076738fd1498Szrj 		error_at (loc,
1076838fd1498Szrj 			  "fixed-point types not supported for this target");
1076938fd1498Szrj 	      pedwarn (loc, OPT_Wpedantic,
1077038fd1498Szrj 		       "ISO C does not support fixed-point types");
1077138fd1498Szrj 	      return specs;
1077238fd1498Szrj 	    default:
1077338fd1498Szrj 	      /* ObjC reserved word "id", handled below.  */
1077438fd1498Szrj 	      break;
1077538fd1498Szrj 	    }
1077638fd1498Szrj 	}
1077738fd1498Szrj     }
1077838fd1498Szrj 
1077938fd1498Szrj   /* Now we have a typedef (a TYPE_DECL node), an identifier (some
1078038fd1498Szrj      form of ObjC type, cases such as "int" and "long" being handled
1078138fd1498Szrj      above), a TYPE (struct, union, enum and typeof specifiers) or an
1078238fd1498Szrj      ERROR_MARK.  In none of these cases may there have previously
1078338fd1498Szrj      been any type specifiers.  */
1078438fd1498Szrj   if (specs->type || specs->typespec_word != cts_none
1078538fd1498Szrj       || specs->long_p || specs->short_p || specs->signed_p
1078638fd1498Szrj       || specs->unsigned_p || specs->complex_p)
1078738fd1498Szrj     error_at (loc, "two or more data types in declaration specifiers");
1078838fd1498Szrj   else if (TREE_CODE (type) == TYPE_DECL)
1078938fd1498Szrj     {
1079038fd1498Szrj       if (TREE_TYPE (type) == error_mark_node)
1079138fd1498Szrj 	; /* Allow the type to default to int to avoid cascading errors.  */
1079238fd1498Szrj       else
1079338fd1498Szrj 	{
1079438fd1498Szrj 	  specs->type = TREE_TYPE (type);
1079538fd1498Szrj 	  specs->decl_attr = DECL_ATTRIBUTES (type);
1079638fd1498Szrj 	  specs->typedef_p = true;
1079738fd1498Szrj 	  specs->explicit_signed_p = C_TYPEDEF_EXPLICITLY_SIGNED (type);
1079838fd1498Szrj 	  specs->locations[cdw_typedef] = loc;
1079938fd1498Szrj 
1080038fd1498Szrj 	  /* If this typedef name is defined in a struct, then a C++
1080138fd1498Szrj 	     lookup would return a different value.  */
1080238fd1498Szrj 	  if (warn_cxx_compat
1080338fd1498Szrj 	      && I_SYMBOL_BINDING (DECL_NAME (type))->in_struct)
1080438fd1498Szrj 	    warning_at (loc, OPT_Wc___compat,
1080538fd1498Szrj 			"C++ lookup of %qD would return a field, not a type",
1080638fd1498Szrj 			type);
1080738fd1498Szrj 
1080838fd1498Szrj 	  /* If we are parsing a struct, record that a struct field
1080938fd1498Szrj 	     used a typedef.  */
1081038fd1498Szrj 	  if (warn_cxx_compat && struct_parse_info != NULL)
1081138fd1498Szrj 	    struct_parse_info->typedefs_seen.safe_push (type);
1081238fd1498Szrj 	}
1081338fd1498Szrj     }
1081438fd1498Szrj   else if (TREE_CODE (type) == IDENTIFIER_NODE)
1081538fd1498Szrj     {
1081638fd1498Szrj       tree t = lookup_name (type);
1081738fd1498Szrj       if (!t || TREE_CODE (t) != TYPE_DECL)
1081838fd1498Szrj 	error_at (loc, "%qE fails to be a typedef or built in type", type);
1081938fd1498Szrj       else if (TREE_TYPE (t) == error_mark_node)
1082038fd1498Szrj 	;
1082138fd1498Szrj       else
1082238fd1498Szrj 	{
1082338fd1498Szrj 	  specs->type = TREE_TYPE (t);
1082438fd1498Szrj 	  specs->locations[cdw_typespec] = loc;
1082538fd1498Szrj 	}
1082638fd1498Szrj     }
1082738fd1498Szrj   else
1082838fd1498Szrj     {
1082938fd1498Szrj       if (TREE_CODE (type) != ERROR_MARK && spec.kind == ctsk_typeof)
1083038fd1498Szrj 	{
1083138fd1498Szrj 	  specs->typedef_p = true;
1083238fd1498Szrj 	  specs->locations[cdw_typedef] = loc;
1083338fd1498Szrj 	  if (spec.expr)
1083438fd1498Szrj 	    {
1083538fd1498Szrj 	      if (specs->expr)
1083638fd1498Szrj 		specs->expr = build2 (COMPOUND_EXPR, TREE_TYPE (spec.expr),
1083738fd1498Szrj 				      specs->expr, spec.expr);
1083838fd1498Szrj 	      else
1083938fd1498Szrj 		specs->expr = spec.expr;
1084038fd1498Szrj 	      specs->expr_const_operands &= spec.expr_const_operands;
1084138fd1498Szrj 	    }
1084238fd1498Szrj 	}
1084338fd1498Szrj       specs->type = type;
1084438fd1498Szrj     }
1084538fd1498Szrj 
1084638fd1498Szrj   return specs;
1084738fd1498Szrj }
1084838fd1498Szrj 
1084938fd1498Szrj /* Add the storage class specifier or function specifier SCSPEC to the
1085038fd1498Szrj    declaration specifiers SPECS, returning SPECS.  */
1085138fd1498Szrj 
1085238fd1498Szrj struct c_declspecs *
declspecs_add_scspec(source_location loc,struct c_declspecs * specs,tree scspec)1085338fd1498Szrj declspecs_add_scspec (source_location loc,
1085438fd1498Szrj 		      struct c_declspecs *specs,
1085538fd1498Szrj 		      tree scspec)
1085638fd1498Szrj {
1085738fd1498Szrj   enum rid i;
1085838fd1498Szrj   enum c_storage_class n = csc_none;
1085938fd1498Szrj   bool dupe = false;
1086038fd1498Szrj   specs->declspecs_seen_p = true;
1086138fd1498Szrj   gcc_assert (TREE_CODE (scspec) == IDENTIFIER_NODE
1086238fd1498Szrj 	      && C_IS_RESERVED_WORD (scspec));
1086338fd1498Szrj   i = C_RID_CODE (scspec);
1086438fd1498Szrj   if (specs->non_sc_seen_p)
1086538fd1498Szrj     warning (OPT_Wold_style_declaration,
1086638fd1498Szrj              "%qE is not at beginning of declaration", scspec);
1086738fd1498Szrj   switch (i)
1086838fd1498Szrj     {
1086938fd1498Szrj     case RID_INLINE:
1087038fd1498Szrj       /* C99 permits duplicate inline.  Although of doubtful utility,
1087138fd1498Szrj 	 it seems simplest to permit it in gnu89 mode as well, as
1087238fd1498Szrj 	 there is also little utility in maintaining this as a
1087338fd1498Szrj 	 difference between gnu89 and C99 inline.  */
1087438fd1498Szrj       dupe = false;
1087538fd1498Szrj       specs->inline_p = true;
1087638fd1498Szrj       specs->locations[cdw_inline] = loc;
1087738fd1498Szrj       break;
1087838fd1498Szrj     case RID_NORETURN:
1087938fd1498Szrj       /* Duplicate _Noreturn is permitted.  */
1088038fd1498Szrj       dupe = false;
1088138fd1498Szrj       specs->noreturn_p = true;
1088238fd1498Szrj       specs->locations[cdw_noreturn] = loc;
1088338fd1498Szrj       break;
1088438fd1498Szrj     case RID_THREAD:
1088538fd1498Szrj       dupe = specs->thread_p;
1088638fd1498Szrj       if (specs->storage_class == csc_auto)
1088738fd1498Szrj 	error ("%qE used with %<auto%>", scspec);
1088838fd1498Szrj       else if (specs->storage_class == csc_register)
1088938fd1498Szrj 	error ("%qE used with %<register%>", scspec);
1089038fd1498Szrj       else if (specs->storage_class == csc_typedef)
1089138fd1498Szrj 	error ("%qE used with %<typedef%>", scspec);
1089238fd1498Szrj       else
1089338fd1498Szrj 	{
1089438fd1498Szrj 	  specs->thread_p = true;
1089538fd1498Szrj 	  specs->thread_gnu_p = (strcmp (IDENTIFIER_POINTER (scspec),
1089638fd1498Szrj 					 "__thread") == 0);
1089738fd1498Szrj 	  /* A diagnostic is not required for the use of this
1089838fd1498Szrj 	     identifier in the implementation namespace; only diagnose
1089938fd1498Szrj 	     it for the C11 spelling because of existing code using
1090038fd1498Szrj 	     the other spelling.  */
1090138fd1498Szrj 	  if (!specs->thread_gnu_p)
1090238fd1498Szrj 	    {
1090338fd1498Szrj 	      if (flag_isoc99)
1090438fd1498Szrj 		pedwarn_c99 (loc, OPT_Wpedantic,
1090538fd1498Szrj 			     "ISO C99 does not support %qE", scspec);
1090638fd1498Szrj 	      else
1090738fd1498Szrj 		pedwarn_c99 (loc, OPT_Wpedantic,
1090838fd1498Szrj 			     "ISO C90 does not support %qE", scspec);
1090938fd1498Szrj 	    }
1091038fd1498Szrj 	  specs->locations[cdw_thread] = loc;
1091138fd1498Szrj 	}
1091238fd1498Szrj       break;
1091338fd1498Szrj     case RID_AUTO:
1091438fd1498Szrj       n = csc_auto;
1091538fd1498Szrj       break;
1091638fd1498Szrj     case RID_EXTERN:
1091738fd1498Szrj       n = csc_extern;
1091838fd1498Szrj       /* Diagnose "__thread extern".  */
1091938fd1498Szrj       if (specs->thread_p && specs->thread_gnu_p)
1092038fd1498Szrj 	error ("%<__thread%> before %<extern%>");
1092138fd1498Szrj       break;
1092238fd1498Szrj     case RID_REGISTER:
1092338fd1498Szrj       n = csc_register;
1092438fd1498Szrj       break;
1092538fd1498Szrj     case RID_STATIC:
1092638fd1498Szrj       n = csc_static;
1092738fd1498Szrj       /* Diagnose "__thread static".  */
1092838fd1498Szrj       if (specs->thread_p && specs->thread_gnu_p)
1092938fd1498Szrj 	error ("%<__thread%> before %<static%>");
1093038fd1498Szrj       break;
1093138fd1498Szrj     case RID_TYPEDEF:
1093238fd1498Szrj       n = csc_typedef;
1093338fd1498Szrj       break;
1093438fd1498Szrj     default:
1093538fd1498Szrj       gcc_unreachable ();
1093638fd1498Szrj     }
1093738fd1498Szrj   if (n != csc_none && n == specs->storage_class)
1093838fd1498Szrj     dupe = true;
1093938fd1498Szrj   if (dupe)
1094038fd1498Szrj     {
1094138fd1498Szrj       if (i == RID_THREAD)
1094238fd1498Szrj 	error ("duplicate %<_Thread_local%> or %<__thread%>");
1094338fd1498Szrj       else
1094438fd1498Szrj 	error ("duplicate %qE", scspec);
1094538fd1498Szrj     }
1094638fd1498Szrj   if (n != csc_none)
1094738fd1498Szrj     {
1094838fd1498Szrj       if (specs->storage_class != csc_none && n != specs->storage_class)
1094938fd1498Szrj 	{
1095038fd1498Szrj 	  error ("multiple storage classes in declaration specifiers");
1095138fd1498Szrj 	}
1095238fd1498Szrj       else
1095338fd1498Szrj 	{
1095438fd1498Szrj 	  specs->storage_class = n;
1095538fd1498Szrj 	  specs->locations[cdw_storage_class] = loc;
1095638fd1498Szrj 	  if (n != csc_extern && n != csc_static && specs->thread_p)
1095738fd1498Szrj 	    {
1095838fd1498Szrj 	      error ("%qs used with %qE",
1095938fd1498Szrj 		     specs->thread_gnu_p ? "__thread" : "_Thread_local",
1096038fd1498Szrj 		     scspec);
1096138fd1498Szrj 	      specs->thread_p = false;
1096238fd1498Szrj 	    }
1096338fd1498Szrj 	}
1096438fd1498Szrj     }
1096538fd1498Szrj   return specs;
1096638fd1498Szrj }
1096738fd1498Szrj 
1096838fd1498Szrj /* Add the attributes ATTRS to the declaration specifiers SPECS,
1096938fd1498Szrj    returning SPECS.  */
1097038fd1498Szrj 
1097138fd1498Szrj struct c_declspecs *
declspecs_add_attrs(source_location loc,struct c_declspecs * specs,tree attrs)1097238fd1498Szrj declspecs_add_attrs (source_location loc, struct c_declspecs *specs, tree attrs)
1097338fd1498Szrj {
1097438fd1498Szrj   specs->attrs = chainon (attrs, specs->attrs);
1097538fd1498Szrj   specs->locations[cdw_attributes] = loc;
1097638fd1498Szrj   specs->declspecs_seen_p = true;
1097738fd1498Szrj   return specs;
1097838fd1498Szrj }
1097938fd1498Szrj 
1098038fd1498Szrj /* Add an _Alignas specifier (expression ALIGN, or type whose
1098138fd1498Szrj    alignment is ALIGN) to the declaration specifiers SPECS, returning
1098238fd1498Szrj    SPECS.  */
1098338fd1498Szrj struct c_declspecs *
declspecs_add_alignas(source_location loc,struct c_declspecs * specs,tree align)1098438fd1498Szrj declspecs_add_alignas (source_location loc,
1098538fd1498Szrj 		       struct c_declspecs *specs, tree align)
1098638fd1498Szrj {
1098738fd1498Szrj   int align_log;
1098838fd1498Szrj   specs->alignas_p = true;
1098938fd1498Szrj   specs->locations[cdw_alignas] = loc;
1099038fd1498Szrj   if (align == error_mark_node)
1099138fd1498Szrj     return specs;
1099238fd1498Szrj   align_log = check_user_alignment (align, true);
1099338fd1498Szrj   if (align_log > specs->align_log)
1099438fd1498Szrj     specs->align_log = align_log;
1099538fd1498Szrj   return specs;
1099638fd1498Szrj }
1099738fd1498Szrj 
1099838fd1498Szrj /* Combine "long", "short", "signed", "unsigned" and "_Complex" type
1099938fd1498Szrj    specifiers with any other type specifier to determine the resulting
1100038fd1498Szrj    type.  This is where ISO C checks on complex types are made, since
1100138fd1498Szrj    "_Complex long" is a prefix of the valid ISO C type "_Complex long
1100238fd1498Szrj    double".  */
1100338fd1498Szrj 
1100438fd1498Szrj struct c_declspecs *
finish_declspecs(struct c_declspecs * specs)1100538fd1498Szrj finish_declspecs (struct c_declspecs *specs)
1100638fd1498Szrj {
1100738fd1498Szrj   /* If a type was specified as a whole, we have no modifiers and are
1100838fd1498Szrj      done.  */
1100938fd1498Szrj   if (specs->type != NULL_TREE)
1101038fd1498Szrj     {
1101138fd1498Szrj       gcc_assert (!specs->long_p && !specs->long_long_p && !specs->short_p
1101238fd1498Szrj 		  && !specs->signed_p && !specs->unsigned_p
1101338fd1498Szrj 		  && !specs->complex_p);
1101438fd1498Szrj 
1101538fd1498Szrj       /* Set a dummy type.  */
1101638fd1498Szrj       if (TREE_CODE (specs->type) == ERROR_MARK)
1101738fd1498Szrj         specs->type = integer_type_node;
1101838fd1498Szrj       return specs;
1101938fd1498Szrj     }
1102038fd1498Szrj 
1102138fd1498Szrj   /* If none of "void", "_Bool", "char", "int", "float" or "double"
1102238fd1498Szrj      has been specified, treat it as "int" unless "_Complex" is
1102338fd1498Szrj      present and there are no other specifiers.  If we just have
1102438fd1498Szrj      "_Complex", it is equivalent to "_Complex double", but e.g.
1102538fd1498Szrj      "_Complex short" is equivalent to "_Complex short int".  */
1102638fd1498Szrj   if (specs->typespec_word == cts_none)
1102738fd1498Szrj     {
1102838fd1498Szrj       if (specs->saturating_p)
1102938fd1498Szrj 	{
1103038fd1498Szrj 	  error_at (specs->locations[cdw_saturating],
1103138fd1498Szrj 		    "%<_Sat%> is used without %<_Fract%> or %<_Accum%>");
1103238fd1498Szrj 	  if (!targetm.fixed_point_supported_p ())
1103338fd1498Szrj 	    error_at (specs->locations[cdw_saturating],
1103438fd1498Szrj 		      "fixed-point types not supported for this target");
1103538fd1498Szrj 	  specs->typespec_word = cts_fract;
1103638fd1498Szrj 	}
1103738fd1498Szrj       else if (specs->long_p || specs->short_p
1103838fd1498Szrj 	       || specs->signed_p || specs->unsigned_p)
1103938fd1498Szrj 	{
1104038fd1498Szrj 	  specs->typespec_word = cts_int;
1104138fd1498Szrj 	}
1104238fd1498Szrj       else if (specs->complex_p)
1104338fd1498Szrj 	{
1104438fd1498Szrj 	  specs->typespec_word = cts_double;
1104538fd1498Szrj 	  pedwarn (specs->locations[cdw_complex], OPT_Wpedantic,
1104638fd1498Szrj 		   "ISO C does not support plain %<complex%> meaning "
1104738fd1498Szrj 		   "%<double complex%>");
1104838fd1498Szrj 	}
1104938fd1498Szrj       else
1105038fd1498Szrj 	{
1105138fd1498Szrj 	  specs->typespec_word = cts_int;
1105238fd1498Szrj 	  specs->default_int_p = true;
1105338fd1498Szrj 	  /* We don't diagnose this here because grokdeclarator will
1105438fd1498Szrj 	     give more specific diagnostics according to whether it is
1105538fd1498Szrj 	     a function definition.  */
1105638fd1498Szrj 	}
1105738fd1498Szrj     }
1105838fd1498Szrj 
1105938fd1498Szrj   /* If "signed" was specified, record this to distinguish "int" and
1106038fd1498Szrj      "signed int" in the case of a bit-field with
1106138fd1498Szrj      -funsigned-bitfields.  */
1106238fd1498Szrj   specs->explicit_signed_p = specs->signed_p;
1106338fd1498Szrj 
1106438fd1498Szrj   /* Now compute the actual type.  */
1106538fd1498Szrj   switch (specs->typespec_word)
1106638fd1498Szrj     {
1106738fd1498Szrj     case cts_auto_type:
1106838fd1498Szrj       gcc_assert (!specs->long_p && !specs->short_p
1106938fd1498Szrj 		  && !specs->signed_p && !specs->unsigned_p
1107038fd1498Szrj 		  && !specs->complex_p);
1107138fd1498Szrj       /* Type to be filled in later.  */
1107238fd1498Szrj       break;
1107338fd1498Szrj     case cts_void:
1107438fd1498Szrj       gcc_assert (!specs->long_p && !specs->short_p
1107538fd1498Szrj 		  && !specs->signed_p && !specs->unsigned_p
1107638fd1498Szrj 		  && !specs->complex_p);
1107738fd1498Szrj       specs->type = void_type_node;
1107838fd1498Szrj       break;
1107938fd1498Szrj     case cts_bool:
1108038fd1498Szrj       gcc_assert (!specs->long_p && !specs->short_p
1108138fd1498Szrj 		  && !specs->signed_p && !specs->unsigned_p
1108238fd1498Szrj 		  && !specs->complex_p);
1108338fd1498Szrj       specs->type = boolean_type_node;
1108438fd1498Szrj       break;
1108538fd1498Szrj     case cts_char:
1108638fd1498Szrj       gcc_assert (!specs->long_p && !specs->short_p);
1108738fd1498Szrj       gcc_assert (!(specs->signed_p && specs->unsigned_p));
1108838fd1498Szrj       if (specs->signed_p)
1108938fd1498Szrj 	specs->type = signed_char_type_node;
1109038fd1498Szrj       else if (specs->unsigned_p)
1109138fd1498Szrj 	specs->type = unsigned_char_type_node;
1109238fd1498Szrj       else
1109338fd1498Szrj 	specs->type = char_type_node;
1109438fd1498Szrj       if (specs->complex_p)
1109538fd1498Szrj 	{
1109638fd1498Szrj 	  pedwarn (specs->locations[cdw_complex], OPT_Wpedantic,
1109738fd1498Szrj 		   "ISO C does not support complex integer types");
1109838fd1498Szrj 	  specs->type = build_complex_type (specs->type);
1109938fd1498Szrj 	}
1110038fd1498Szrj       break;
1110138fd1498Szrj     case cts_int_n:
1110238fd1498Szrj       gcc_assert (!specs->long_p && !specs->short_p && !specs->long_long_p);
1110338fd1498Szrj       gcc_assert (!(specs->signed_p && specs->unsigned_p));
1110438fd1498Szrj       if (! int_n_enabled_p[specs->int_n_idx])
1110538fd1498Szrj 	specs->type = integer_type_node;
1110638fd1498Szrj       else
1110738fd1498Szrj 	specs->type = (specs->unsigned_p
1110838fd1498Szrj 		       ? int_n_trees[specs->int_n_idx].unsigned_type
1110938fd1498Szrj 		       : int_n_trees[specs->int_n_idx].signed_type);
1111038fd1498Szrj       if (specs->complex_p)
1111138fd1498Szrj 	{
1111238fd1498Szrj 	  pedwarn (specs->locations[cdw_complex], OPT_Wpedantic,
1111338fd1498Szrj 		   "ISO C does not support complex integer types");
1111438fd1498Szrj 	  specs->type = build_complex_type (specs->type);
1111538fd1498Szrj 	}
1111638fd1498Szrj       break;
1111738fd1498Szrj     case cts_int:
1111838fd1498Szrj       gcc_assert (!(specs->long_p && specs->short_p));
1111938fd1498Szrj       gcc_assert (!(specs->signed_p && specs->unsigned_p));
1112038fd1498Szrj       if (specs->long_long_p)
1112138fd1498Szrj 	specs->type = (specs->unsigned_p
1112238fd1498Szrj 		       ? long_long_unsigned_type_node
1112338fd1498Szrj 		       : long_long_integer_type_node);
1112438fd1498Szrj       else if (specs->long_p)
1112538fd1498Szrj 	specs->type = (specs->unsigned_p
1112638fd1498Szrj 		       ? long_unsigned_type_node
1112738fd1498Szrj 		       : long_integer_type_node);
1112838fd1498Szrj       else if (specs->short_p)
1112938fd1498Szrj 	specs->type = (specs->unsigned_p
1113038fd1498Szrj 		       ? short_unsigned_type_node
1113138fd1498Szrj 		       : short_integer_type_node);
1113238fd1498Szrj       else
1113338fd1498Szrj 	specs->type = (specs->unsigned_p
1113438fd1498Szrj 		       ? unsigned_type_node
1113538fd1498Szrj 		       : integer_type_node);
1113638fd1498Szrj       if (specs->complex_p)
1113738fd1498Szrj 	{
1113838fd1498Szrj 	  pedwarn (specs->locations[cdw_complex], OPT_Wpedantic,
1113938fd1498Szrj 		   "ISO C does not support complex integer types");
1114038fd1498Szrj 	  specs->type = build_complex_type (specs->type);
1114138fd1498Szrj 	}
1114238fd1498Szrj       break;
1114338fd1498Szrj     case cts_float:
1114438fd1498Szrj       gcc_assert (!specs->long_p && !specs->short_p
1114538fd1498Szrj 		  && !specs->signed_p && !specs->unsigned_p);
1114638fd1498Szrj       specs->type = (specs->complex_p
1114738fd1498Szrj 		     ? complex_float_type_node
1114838fd1498Szrj 		     : float_type_node);
1114938fd1498Szrj       break;
1115038fd1498Szrj     case cts_double:
1115138fd1498Szrj       gcc_assert (!specs->long_long_p && !specs->short_p
1115238fd1498Szrj 		  && !specs->signed_p && !specs->unsigned_p);
1115338fd1498Szrj       if (specs->long_p)
1115438fd1498Szrj 	{
1115538fd1498Szrj 	  specs->type = (specs->complex_p
1115638fd1498Szrj 			 ? complex_long_double_type_node
1115738fd1498Szrj 			 : long_double_type_node);
1115838fd1498Szrj 	}
1115938fd1498Szrj       else
1116038fd1498Szrj 	{
1116138fd1498Szrj 	  specs->type = (specs->complex_p
1116238fd1498Szrj 			 ? complex_double_type_node
1116338fd1498Szrj 			 : double_type_node);
1116438fd1498Szrj 	}
1116538fd1498Szrj       break;
1116638fd1498Szrj     case cts_floatn_nx:
1116738fd1498Szrj       gcc_assert (!specs->long_p && !specs->short_p
1116838fd1498Szrj 		  && !specs->signed_p && !specs->unsigned_p);
1116938fd1498Szrj       if (FLOATN_NX_TYPE_NODE (specs->floatn_nx_idx) == NULL_TREE)
1117038fd1498Szrj 	specs->type = integer_type_node;
1117138fd1498Szrj       else if (specs->complex_p)
1117238fd1498Szrj 	specs->type = COMPLEX_FLOATN_NX_TYPE_NODE (specs->floatn_nx_idx);
1117338fd1498Szrj       else
1117438fd1498Szrj 	specs->type = FLOATN_NX_TYPE_NODE (specs->floatn_nx_idx);
1117538fd1498Szrj       break;
1117638fd1498Szrj     case cts_dfloat32:
1117738fd1498Szrj     case cts_dfloat64:
1117838fd1498Szrj     case cts_dfloat128:
1117938fd1498Szrj       gcc_assert (!specs->long_p && !specs->long_long_p && !specs->short_p
1118038fd1498Szrj 		  && !specs->signed_p && !specs->unsigned_p && !specs->complex_p);
1118138fd1498Szrj       if (specs->typespec_word == cts_dfloat32)
1118238fd1498Szrj 	specs->type = dfloat32_type_node;
1118338fd1498Szrj       else if (specs->typespec_word == cts_dfloat64)
1118438fd1498Szrj 	specs->type = dfloat64_type_node;
1118538fd1498Szrj       else
1118638fd1498Szrj 	specs->type = dfloat128_type_node;
1118738fd1498Szrj       break;
1118838fd1498Szrj     case cts_fract:
1118938fd1498Szrj       gcc_assert (!specs->complex_p);
1119038fd1498Szrj       if (!targetm.fixed_point_supported_p ())
1119138fd1498Szrj 	specs->type = integer_type_node;
1119238fd1498Szrj       else if (specs->saturating_p)
1119338fd1498Szrj 	{
1119438fd1498Szrj 	  if (specs->long_long_p)
1119538fd1498Szrj 	    specs->type = specs->unsigned_p
1119638fd1498Szrj 			  ? sat_unsigned_long_long_fract_type_node
1119738fd1498Szrj 			  : sat_long_long_fract_type_node;
1119838fd1498Szrj 	  else if (specs->long_p)
1119938fd1498Szrj 	    specs->type = specs->unsigned_p
1120038fd1498Szrj 			  ? sat_unsigned_long_fract_type_node
1120138fd1498Szrj 			  : sat_long_fract_type_node;
1120238fd1498Szrj 	  else if (specs->short_p)
1120338fd1498Szrj 	    specs->type = specs->unsigned_p
1120438fd1498Szrj 			  ? sat_unsigned_short_fract_type_node
1120538fd1498Szrj 			  : sat_short_fract_type_node;
1120638fd1498Szrj 	  else
1120738fd1498Szrj 	    specs->type = specs->unsigned_p
1120838fd1498Szrj 			  ? sat_unsigned_fract_type_node
1120938fd1498Szrj 			  : sat_fract_type_node;
1121038fd1498Szrj 	}
1121138fd1498Szrj       else
1121238fd1498Szrj 	{
1121338fd1498Szrj 	  if (specs->long_long_p)
1121438fd1498Szrj 	    specs->type = specs->unsigned_p
1121538fd1498Szrj 			  ? unsigned_long_long_fract_type_node
1121638fd1498Szrj 			  : long_long_fract_type_node;
1121738fd1498Szrj 	  else if (specs->long_p)
1121838fd1498Szrj 	    specs->type = specs->unsigned_p
1121938fd1498Szrj 			  ? unsigned_long_fract_type_node
1122038fd1498Szrj 			  : long_fract_type_node;
1122138fd1498Szrj 	  else if (specs->short_p)
1122238fd1498Szrj 	    specs->type = specs->unsigned_p
1122338fd1498Szrj 			  ? unsigned_short_fract_type_node
1122438fd1498Szrj 			  : short_fract_type_node;
1122538fd1498Szrj 	  else
1122638fd1498Szrj 	    specs->type = specs->unsigned_p
1122738fd1498Szrj 			  ? unsigned_fract_type_node
1122838fd1498Szrj 			  : fract_type_node;
1122938fd1498Szrj 	}
1123038fd1498Szrj       break;
1123138fd1498Szrj     case cts_accum:
1123238fd1498Szrj       gcc_assert (!specs->complex_p);
1123338fd1498Szrj       if (!targetm.fixed_point_supported_p ())
1123438fd1498Szrj 	specs->type = integer_type_node;
1123538fd1498Szrj       else if (specs->saturating_p)
1123638fd1498Szrj 	{
1123738fd1498Szrj 	  if (specs->long_long_p)
1123838fd1498Szrj 	    specs->type = specs->unsigned_p
1123938fd1498Szrj 			  ? sat_unsigned_long_long_accum_type_node
1124038fd1498Szrj 			  : sat_long_long_accum_type_node;
1124138fd1498Szrj 	  else if (specs->long_p)
1124238fd1498Szrj 	    specs->type = specs->unsigned_p
1124338fd1498Szrj 			  ? sat_unsigned_long_accum_type_node
1124438fd1498Szrj 			  : sat_long_accum_type_node;
1124538fd1498Szrj 	  else if (specs->short_p)
1124638fd1498Szrj 	    specs->type = specs->unsigned_p
1124738fd1498Szrj 			  ? sat_unsigned_short_accum_type_node
1124838fd1498Szrj 			  : sat_short_accum_type_node;
1124938fd1498Szrj 	  else
1125038fd1498Szrj 	    specs->type = specs->unsigned_p
1125138fd1498Szrj 			  ? sat_unsigned_accum_type_node
1125238fd1498Szrj 			  : sat_accum_type_node;
1125338fd1498Szrj 	}
1125438fd1498Szrj       else
1125538fd1498Szrj 	{
1125638fd1498Szrj 	  if (specs->long_long_p)
1125738fd1498Szrj 	    specs->type = specs->unsigned_p
1125838fd1498Szrj 			  ? unsigned_long_long_accum_type_node
1125938fd1498Szrj 			  : long_long_accum_type_node;
1126038fd1498Szrj 	  else if (specs->long_p)
1126138fd1498Szrj 	    specs->type = specs->unsigned_p
1126238fd1498Szrj 			  ? unsigned_long_accum_type_node
1126338fd1498Szrj 			  : long_accum_type_node;
1126438fd1498Szrj 	  else if (specs->short_p)
1126538fd1498Szrj 	    specs->type = specs->unsigned_p
1126638fd1498Szrj 			  ? unsigned_short_accum_type_node
1126738fd1498Szrj 			  : short_accum_type_node;
1126838fd1498Szrj 	  else
1126938fd1498Szrj 	    specs->type = specs->unsigned_p
1127038fd1498Szrj 			  ? unsigned_accum_type_node
1127138fd1498Szrj 			  : accum_type_node;
1127238fd1498Szrj 	}
1127338fd1498Szrj       break;
1127438fd1498Szrj     default:
1127538fd1498Szrj       gcc_unreachable ();
1127638fd1498Szrj     }
1127738fd1498Szrj 
1127838fd1498Szrj   return specs;
1127938fd1498Szrj }
1128038fd1498Szrj 
1128138fd1498Szrj /* Perform final processing on one file scope's declarations (or the
1128238fd1498Szrj    external scope's declarations), GLOBALS.  */
1128338fd1498Szrj 
1128438fd1498Szrj static void
c_write_global_declarations_1(tree globals)1128538fd1498Szrj c_write_global_declarations_1 (tree globals)
1128638fd1498Szrj {
1128738fd1498Szrj   tree decl;
1128838fd1498Szrj   bool reconsider;
1128938fd1498Szrj 
1129038fd1498Szrj   /* Process the decls in the order they were written.  */
1129138fd1498Szrj   for (decl = globals; decl; decl = DECL_CHAIN (decl))
1129238fd1498Szrj     {
1129338fd1498Szrj       /* Check for used but undefined static functions using the C
1129438fd1498Szrj 	 standard's definition of "used", and set TREE_NO_WARNING so
1129538fd1498Szrj 	 that check_global_declaration doesn't repeat the check.  */
1129638fd1498Szrj       if (TREE_CODE (decl) == FUNCTION_DECL
1129738fd1498Szrj 	  && DECL_INITIAL (decl) == NULL_TREE
1129838fd1498Szrj 	  && DECL_EXTERNAL (decl)
1129938fd1498Szrj 	  && !TREE_PUBLIC (decl))
1130038fd1498Szrj 	{
1130138fd1498Szrj 	  if (C_DECL_USED (decl))
1130238fd1498Szrj 	    {
1130338fd1498Szrj 	      pedwarn (input_location, 0, "%q+F used but never defined", decl);
1130438fd1498Szrj 	      TREE_NO_WARNING (decl) = 1;
1130538fd1498Szrj 	    }
1130638fd1498Szrj 	  /* For -Wunused-function warn about unused static prototypes.  */
1130738fd1498Szrj 	  else if (warn_unused_function
1130838fd1498Szrj 		   && ! DECL_ARTIFICIAL (decl)
1130938fd1498Szrj 		   && ! TREE_NO_WARNING (decl))
1131038fd1498Szrj 	    {
1131138fd1498Szrj 	      warning (OPT_Wunused_function,
1131238fd1498Szrj 		       "%q+F declared %<static%> but never defined", decl);
1131338fd1498Szrj 	      TREE_NO_WARNING (decl) = 1;
1131438fd1498Szrj 	    }
1131538fd1498Szrj 	}
1131638fd1498Szrj 
1131738fd1498Szrj       wrapup_global_declaration_1 (decl);
1131838fd1498Szrj     }
1131938fd1498Szrj 
1132038fd1498Szrj   do
1132138fd1498Szrj     {
1132238fd1498Szrj       reconsider = false;
1132338fd1498Szrj       for (decl = globals; decl; decl = DECL_CHAIN (decl))
1132438fd1498Szrj 	reconsider |= wrapup_global_declaration_2 (decl);
1132538fd1498Szrj     }
1132638fd1498Szrj   while (reconsider);
1132738fd1498Szrj }
1132838fd1498Szrj 
1132938fd1498Szrj /* Callback to collect a source_ref from a DECL.  */
1133038fd1498Szrj 
1133138fd1498Szrj static void
collect_source_ref_cb(tree decl)1133238fd1498Szrj collect_source_ref_cb (tree decl)
1133338fd1498Szrj {
1133438fd1498Szrj   if (!DECL_IS_BUILTIN (decl))
1133538fd1498Szrj     collect_source_ref (LOCATION_FILE (decl_sloc (decl, false)));
1133638fd1498Szrj }
1133738fd1498Szrj 
1133838fd1498Szrj /* Preserve the external declarations scope across a garbage collect.  */
1133938fd1498Szrj static GTY(()) tree ext_block;
1134038fd1498Szrj 
1134138fd1498Szrj /* Collect all references relevant to SOURCE_FILE.  */
1134238fd1498Szrj 
1134338fd1498Szrj static void
collect_all_refs(const char * source_file)1134438fd1498Szrj collect_all_refs (const char *source_file)
1134538fd1498Szrj {
1134638fd1498Szrj   tree t;
1134738fd1498Szrj   unsigned i;
1134838fd1498Szrj 
1134938fd1498Szrj   FOR_EACH_VEC_ELT (*all_translation_units, i, t)
1135038fd1498Szrj     collect_ada_nodes (BLOCK_VARS (DECL_INITIAL (t)), source_file);
1135138fd1498Szrj 
1135238fd1498Szrj   collect_ada_nodes (BLOCK_VARS (ext_block), source_file);
1135338fd1498Szrj }
1135438fd1498Szrj 
1135538fd1498Szrj /* Iterate over all global declarations and call CALLBACK.  */
1135638fd1498Szrj 
1135738fd1498Szrj static void
for_each_global_decl(void (* callback)(tree decl))1135838fd1498Szrj for_each_global_decl (void (*callback) (tree decl))
1135938fd1498Szrj {
1136038fd1498Szrj   tree t;
1136138fd1498Szrj   tree decls;
1136238fd1498Szrj   tree decl;
1136338fd1498Szrj   unsigned i;
1136438fd1498Szrj 
1136538fd1498Szrj   FOR_EACH_VEC_ELT (*all_translation_units, i, t)
1136638fd1498Szrj     {
1136738fd1498Szrj       decls = DECL_INITIAL (t);
1136838fd1498Szrj       for (decl = BLOCK_VARS (decls); decl; decl = TREE_CHAIN (decl))
1136938fd1498Szrj 	callback (decl);
1137038fd1498Szrj     }
1137138fd1498Szrj 
1137238fd1498Szrj   for (decl = BLOCK_VARS (ext_block); decl; decl = TREE_CHAIN (decl))
1137338fd1498Szrj     callback (decl);
1137438fd1498Szrj }
1137538fd1498Szrj 
1137638fd1498Szrj /* Perform any final parser cleanups and generate initial debugging
1137738fd1498Szrj    information.  */
1137838fd1498Szrj 
1137938fd1498Szrj void
c_parse_final_cleanups(void)1138038fd1498Szrj c_parse_final_cleanups (void)
1138138fd1498Szrj {
1138238fd1498Szrj   tree t;
1138338fd1498Szrj   unsigned i;
1138438fd1498Szrj 
1138538fd1498Szrj   /* We don't want to do this if generating a PCH.  */
1138638fd1498Szrj   if (pch_file)
1138738fd1498Szrj     return;
1138838fd1498Szrj 
1138938fd1498Szrj   timevar_stop (TV_PHASE_PARSING);
1139038fd1498Szrj   timevar_start (TV_PHASE_DEFERRED);
1139138fd1498Szrj 
1139238fd1498Szrj   /* Do the Objective-C stuff.  This is where all the Objective-C
1139338fd1498Szrj      module stuff gets generated (symtab, class/protocol/selector
1139438fd1498Szrj      lists etc).  */
1139538fd1498Szrj   if (c_dialect_objc ())
1139638fd1498Szrj     objc_write_global_declarations ();
1139738fd1498Szrj 
1139838fd1498Szrj   /* Close the external scope.  */
1139938fd1498Szrj   ext_block = pop_scope ();
1140038fd1498Szrj   external_scope = 0;
1140138fd1498Szrj   gcc_assert (!current_scope);
1140238fd1498Szrj 
1140338fd1498Szrj   /* Handle -fdump-ada-spec[-slim]. */
1140438fd1498Szrj   if (flag_dump_ada_spec || flag_dump_ada_spec_slim)
1140538fd1498Szrj     {
1140638fd1498Szrj       /* Build a table of files to generate specs for */
1140738fd1498Szrj       if (flag_dump_ada_spec_slim)
1140838fd1498Szrj 	collect_source_ref (main_input_filename);
1140938fd1498Szrj       else
1141038fd1498Szrj 	for_each_global_decl (collect_source_ref_cb);
1141138fd1498Szrj 
1141238fd1498Szrj       dump_ada_specs (collect_all_refs, NULL);
1141338fd1498Szrj     }
1141438fd1498Szrj 
1141538fd1498Szrj   /* Process all file scopes in this compilation, and the external_scope,
1141638fd1498Szrj      through wrapup_global_declarations.  */
1141738fd1498Szrj   FOR_EACH_VEC_ELT (*all_translation_units, i, t)
1141838fd1498Szrj     c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t)));
1141938fd1498Szrj   c_write_global_declarations_1 (BLOCK_VARS (ext_block));
1142038fd1498Szrj 
1142138fd1498Szrj   timevar_stop (TV_PHASE_DEFERRED);
1142238fd1498Szrj   timevar_start (TV_PHASE_PARSING);
1142338fd1498Szrj 
1142438fd1498Szrj   ext_block = NULL;
1142538fd1498Szrj }
1142638fd1498Szrj 
1142738fd1498Szrj /* Register reserved keyword WORD as qualifier for address space AS.  */
1142838fd1498Szrj 
1142938fd1498Szrj void
c_register_addr_space(const char * word,addr_space_t as)1143038fd1498Szrj c_register_addr_space (const char *word, addr_space_t as)
1143138fd1498Szrj {
1143238fd1498Szrj   int rid = RID_FIRST_ADDR_SPACE + as;
1143338fd1498Szrj   tree id;
1143438fd1498Szrj 
1143538fd1498Szrj   /* Address space qualifiers are only supported
1143638fd1498Szrj      in C with GNU extensions enabled.  */
1143738fd1498Szrj   if (c_dialect_objc () || flag_no_asm)
1143838fd1498Szrj     return;
1143938fd1498Szrj 
1144038fd1498Szrj   id = get_identifier (word);
1144138fd1498Szrj   C_SET_RID_CODE (id, rid);
1144238fd1498Szrj   C_IS_RESERVED_WORD (id) = 1;
1144338fd1498Szrj   ridpointers [rid] = id;
1144438fd1498Szrj }
1144538fd1498Szrj 
1144638fd1498Szrj /* Return identifier to look up for omp declare reduction.  */
1144738fd1498Szrj 
1144838fd1498Szrj tree
c_omp_reduction_id(enum tree_code reduction_code,tree reduction_id)1144938fd1498Szrj c_omp_reduction_id (enum tree_code reduction_code, tree reduction_id)
1145038fd1498Szrj {
1145138fd1498Szrj   const char *p = NULL;
1145238fd1498Szrj   switch (reduction_code)
1145338fd1498Szrj     {
1145438fd1498Szrj     case PLUS_EXPR: p = "+"; break;
1145538fd1498Szrj     case MULT_EXPR: p = "*"; break;
1145638fd1498Szrj     case MINUS_EXPR: p = "-"; break;
1145738fd1498Szrj     case BIT_AND_EXPR: p = "&"; break;
1145838fd1498Szrj     case BIT_XOR_EXPR: p = "^"; break;
1145938fd1498Szrj     case BIT_IOR_EXPR: p = "|"; break;
1146038fd1498Szrj     case TRUTH_ANDIF_EXPR: p = "&&"; break;
1146138fd1498Szrj     case TRUTH_ORIF_EXPR: p = "||"; break;
1146238fd1498Szrj     case MIN_EXPR: p = "min"; break;
1146338fd1498Szrj     case MAX_EXPR: p = "max"; break;
1146438fd1498Szrj     default:
1146538fd1498Szrj       break;
1146638fd1498Szrj     }
1146738fd1498Szrj 
1146838fd1498Szrj   if (p == NULL)
1146938fd1498Szrj     {
1147038fd1498Szrj       if (TREE_CODE (reduction_id) != IDENTIFIER_NODE)
1147138fd1498Szrj 	return error_mark_node;
1147238fd1498Szrj       p = IDENTIFIER_POINTER (reduction_id);
1147338fd1498Szrj     }
1147438fd1498Szrj 
1147538fd1498Szrj   const char prefix[] = "omp declare reduction ";
1147638fd1498Szrj   size_t lenp = sizeof (prefix);
1147738fd1498Szrj   size_t len = strlen (p);
1147838fd1498Szrj   char *name = XALLOCAVEC (char, lenp + len);
1147938fd1498Szrj   memcpy (name, prefix, lenp - 1);
1148038fd1498Szrj   memcpy (name + lenp - 1, p, len + 1);
1148138fd1498Szrj   return get_identifier (name);
1148238fd1498Szrj }
1148338fd1498Szrj 
1148438fd1498Szrj /* Lookup REDUCTION_ID in the current scope, or create an artificial
1148538fd1498Szrj    VAR_DECL, bind it into the current scope and return it.  */
1148638fd1498Szrj 
1148738fd1498Szrj tree
c_omp_reduction_decl(tree reduction_id)1148838fd1498Szrj c_omp_reduction_decl (tree reduction_id)
1148938fd1498Szrj {
1149038fd1498Szrj   struct c_binding *b = I_SYMBOL_BINDING (reduction_id);
1149138fd1498Szrj   if (b != NULL && B_IN_CURRENT_SCOPE (b))
1149238fd1498Szrj     return b->decl;
1149338fd1498Szrj 
1149438fd1498Szrj   tree decl = build_decl (BUILTINS_LOCATION, VAR_DECL,
1149538fd1498Szrj 			  reduction_id, integer_type_node);
1149638fd1498Szrj   DECL_ARTIFICIAL (decl) = 1;
1149738fd1498Szrj   DECL_EXTERNAL (decl) = 1;
1149838fd1498Szrj   TREE_STATIC (decl) = 1;
1149938fd1498Szrj   TREE_PUBLIC (decl) = 0;
1150038fd1498Szrj   bind (reduction_id, decl, current_scope, true, false, BUILTINS_LOCATION);
1150138fd1498Szrj   return decl;
1150238fd1498Szrj }
1150338fd1498Szrj 
1150438fd1498Szrj /* Lookup REDUCTION_ID in the first scope where it has entry for TYPE.  */
1150538fd1498Szrj 
1150638fd1498Szrj tree
c_omp_reduction_lookup(tree reduction_id,tree type)1150738fd1498Szrj c_omp_reduction_lookup (tree reduction_id, tree type)
1150838fd1498Szrj {
1150938fd1498Szrj   struct c_binding *b = I_SYMBOL_BINDING (reduction_id);
1151038fd1498Szrj   while (b)
1151138fd1498Szrj     {
1151238fd1498Szrj       tree t;
1151338fd1498Szrj       for (t = DECL_INITIAL (b->decl); t; t = TREE_CHAIN (t))
1151438fd1498Szrj 	if (comptypes (TREE_PURPOSE (t), type))
1151538fd1498Szrj 	  return TREE_VALUE (t);
1151638fd1498Szrj       b = b->shadowed;
1151738fd1498Szrj     }
1151838fd1498Szrj   return error_mark_node;
1151938fd1498Szrj }
1152038fd1498Szrj 
1152138fd1498Szrj /* Helper function called via walk_tree, to diagnose invalid
1152238fd1498Szrj    #pragma omp declare reduction combiners or initializers.  */
1152338fd1498Szrj 
1152438fd1498Szrj tree
c_check_omp_declare_reduction_r(tree * tp,int *,void * data)1152538fd1498Szrj c_check_omp_declare_reduction_r (tree *tp, int *, void *data)
1152638fd1498Szrj {
1152738fd1498Szrj   tree *vars = (tree *) data;
1152838fd1498Szrj   if (SSA_VAR_P (*tp)
1152938fd1498Szrj       && !DECL_ARTIFICIAL (*tp)
1153038fd1498Szrj       && *tp != vars[0]
1153138fd1498Szrj       && *tp != vars[1])
1153238fd1498Szrj     {
1153338fd1498Szrj       location_t loc = DECL_SOURCE_LOCATION (vars[0]);
1153438fd1498Szrj       if (strcmp (IDENTIFIER_POINTER (DECL_NAME (vars[0])), "omp_out") == 0)
1153538fd1498Szrj 	error_at (loc, "%<#pragma omp declare reduction%> combiner refers to "
1153638fd1498Szrj 		       "variable %qD which is not %<omp_out%> nor %<omp_in%>",
1153738fd1498Szrj 		  *tp);
1153838fd1498Szrj       else
1153938fd1498Szrj 	error_at (loc, "%<#pragma omp declare reduction%> initializer refers "
1154038fd1498Szrj 		       "to variable %qD which is not %<omp_priv%> nor "
1154138fd1498Szrj 		       "%<omp_orig%>",
1154238fd1498Szrj 		  *tp);
1154338fd1498Szrj       return *tp;
1154438fd1498Szrj     }
1154538fd1498Szrj   return NULL_TREE;
1154638fd1498Szrj }
1154738fd1498Szrj 
1154838fd1498Szrj #include "gt-c-c-decl.h"
11549