• Main Page
  • Modules
  • Data Types
  • Files

osprey-gcc/gcc/c-decl.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006. QLogic Corporation. All Rights Reserved.
00003  */
00004 
00005 /* Process declarations and variables for C compiler.
00006    Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
00007    2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
00008 
00009 This file is part of GCC.
00010 
00011 GCC is free software; you can redistribute it and/or modify it under
00012 the terms of the GNU General Public License as published by the Free
00013 Software Foundation; either version 2, or (at your option) any later
00014 version.
00015 
00016 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
00017 WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019 for more details.
00020 
00021 You should have received a copy of the GNU General Public License
00022 along with GCC; see the file COPYING.  If not, write to the Free
00023 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
00024 02111-1307, USA.  */
00025 
00026 /* Process declarations and symbol lookup for C front end.
00027    Also constructs types; the standard scalar types at initialization,
00028    and structure, union, array and enum types when they are declared.  */
00029 
00030 /* ??? not all decl nodes are given the most useful possible
00031    line numbers.  For example, the CONST_DECLs for enum values.  */
00032 
00033 #include "config.h"
00034 #include "system.h"
00035 #include "coretypes.h"
00036 #include "input.h"
00037 #include "tm.h"
00038 #include "intl.h"
00039 #include "tree.h"
00040 #include "tree-inline.h"
00041 #include "rtl.h"
00042 #include "flags.h"
00043 #include "function.h"
00044 #include "output.h"
00045 #include "expr.h"
00046 #include "c-tree.h"
00047 #include "toplev.h"
00048 #include "ggc.h"
00049 #include "tm_p.h"
00050 #include "cpplib.h"
00051 #include "target.h"
00052 #include "debug.h"
00053 #include "opts.h"
00054 #include "timevar.h"
00055 #include "c-common.h"
00056 #include "c-pragma.h"
00057 #include "langhooks.h"
00058 #include "tree-mudflap.h"
00059 #include "tree-gimple.h"
00060 #include "diagnostic.h"
00061 #include "tree-dump.h"
00062 #include "cgraph.h"
00063 #include "hashtab.h"
00064 #include "libfuncs.h"
00065 #include "except.h"
00066 #include "langhooks-def.h"
00067 
00068 /* In grokdeclarator, distinguish syntactic contexts of declarators.  */
00069 enum decl_context
00070 { NORMAL,     /* Ordinary declaration */
00071   FUNCDEF,      /* Function definition */
00072   PARM,       /* Declaration of parm before function body */
00073   FIELD,      /* Declaration inside struct or union */
00074   TYPENAME};      /* Typename (inside cast or sizeof)  */
00075 
00076 
00077 /* Nonzero if we have seen an invalid cross reference
00078    to a struct, union, or enum, but not yet printed the message.  */
00079 tree pending_invalid_xref;
00080 
00081 /* File and line to appear in the eventual error message.  */
00082 location_t pending_invalid_xref_location;
00083 
00084 /* True means we've initialized exception handling.  */
00085 bool c_eh_initialized_p;
00086 
00087 /* While defining an enum type, this is 1 plus the last enumerator
00088    constant value.  Note that will do not have to save this or `enum_overflow'
00089    around nested function definition since such a definition could only
00090    occur in an enum value expression and we don't use these variables in
00091    that case.  */
00092 
00093 static tree enum_next_value;
00094 
00095 /* Nonzero means that there was overflow computing enum_next_value.  */
00096 
00097 static int enum_overflow;
00098 
00099 /* The file and line that the prototype came from if this is an
00100    old-style definition; used for diagnostics in
00101    store_parm_decls_oldstyle.  */
00102 
00103 static location_t current_function_prototype_locus;
00104 
00105 /* Whether this prototype was built-in.  */
00106 
00107 static bool current_function_prototype_built_in;
00108 
00109 /* The argument type information of this prototype.  */
00110 
00111 static tree current_function_prototype_arg_types;
00112 
00113 /* The argument information structure for the function currently being
00114    defined.  */
00115 
00116 static struct c_arg_info *current_function_arg_info;
00117 
00118 /* The obstack on which parser and related data structures, which are
00119    not live beyond their top-level declaration or definition, are
00120    allocated.  */
00121 struct obstack parser_obstack;
00122 
00123 /* The current statement tree.  */
00124 
00125 static GTY(()) struct stmt_tree_s c_stmt_tree;
00126 
00127 /* State saving variables.  */
00128 tree c_break_label;
00129 tree c_cont_label;
00130 
00131 /* Linked list of TRANSLATION_UNIT_DECLS for the translation units
00132    included in this invocation.  Note that the current translation
00133    unit is not included in this list.  */
00134 
00135 static GTY(()) tree all_translation_units;
00136 
00137 /* A list of decls to be made automatically visible in each file scope.  */
00138 static GTY(()) tree visible_builtins;
00139 
00140 /* Set to 0 at beginning of a function definition, set to 1 if
00141    a return statement that specifies a return value is seen.  */
00142 
00143 int current_function_returns_value;
00144 
00145 /* Set to 0 at beginning of a function definition, set to 1 if
00146    a return statement with no argument is seen.  */
00147 
00148 int current_function_returns_null;
00149 
00150 /* Set to 0 at beginning of a function definition, set to 1 if
00151    a call to a noreturn function is seen.  */
00152 
00153 int current_function_returns_abnormally;
00154 
00155 /* Set to nonzero by `grokdeclarator' for a function
00156    whose return type is defaulted, if warnings for this are desired.  */
00157 
00158 static int warn_about_return_type;
00159 
00160 /* Nonzero when starting a function declared `extern inline'.  */
00161 
00162 static int current_extern_inline;
00163 
00164 /* Nonzero when the current toplevel function contains a declaration
00165    of a nested function which is never defined.  */
00166 
00167 static bool undef_nested_function;
00168 
00169 /* True means global_bindings_p should return false even if the scope stack
00170    says we are in file scope.  */
00171 bool c_override_global_bindings_to_false;
00172 
00173 
00174 /* Each c_binding structure describes one binding of an identifier to
00175    a decl.  All the decls in a scope - irrespective of namespace - are
00176    chained together by the ->prev field, which (as the name implies)
00177    runs in reverse order.  All the decls in a given namespace bound to
00178    a given identifier are chained by the ->shadowed field, which runs
00179    from inner to outer scopes.
00180 
00181    The ->decl field usually points to a DECL node, but there are two
00182    exceptions.  In the namespace of type tags, the bound entity is a
00183    RECORD_TYPE, UNION_TYPE, or ENUMERAL_TYPE node.  If an undeclared
00184    identifier is encountered, it is bound to error_mark_node to
00185    suppress further errors about that identifier in the current
00186    function.
00187 
00188    The ->type field stores the type of the declaration in this scope;
00189    if NULL, the type is the type of the ->decl field.  This is only of
00190    relevance for objects with external or internal linkage which may
00191    be redeclared in inner scopes, forming composite types that only
00192    persist for the duration of those scopes.  In the external scope,
00193    this stores the composite of all the types declared for this
00194    object, visible or not.  The ->inner_comp field (used only at file
00195    scope) stores whether an incomplete array type at file scope was
00196    completed at an inner scope to an array size other than 1.
00197 
00198    The depth field is copied from the scope structure that holds this
00199    decl.  It is used to preserve the proper ordering of the ->shadowed
00200    field (see bind()) and also for a handful of special-case checks.
00201    Finally, the invisible bit is true for a decl which should be
00202    ignored for purposes of normal name lookup, and the nested bit is
00203    true for a decl that's been bound a second time in an inner scope;
00204    in all such cases, the binding in the outer scope will have its
00205    invisible bit true.  */
00206 
00207 struct c_binding GTY((chain_next ("%h.prev")))
00208 {
00209   tree decl;      /* the decl bound */
00210   tree type;      /* the type in this scope */
00211   tree id;      /* the identifier it's bound to */
00212   struct c_binding *prev; /* the previous decl in this scope */
00213   struct c_binding *shadowed; /* the innermost decl shadowed by this one */
00214   unsigned int depth : 28;      /* depth of this scope */
00215   BOOL_BITFIELD invisible : 1;  /* normal lookup should ignore this binding */
00216   BOOL_BITFIELD nested : 1;     /* do not set DECL_CONTEXT when popping */
00217   BOOL_BITFIELD inner_comp : 1; /* incomplete array completed in inner scope */
00218   /* one free bit */
00219 };
00220 #define B_IN_SCOPE(b1, b2) ((b1)->depth == (b2)->depth)
00221 #define B_IN_CURRENT_SCOPE(b) ((b)->depth == current_scope->depth)
00222 #define B_IN_FILE_SCOPE(b) ((b)->depth == 1 /*file_scope->depth*/)
00223 #define B_IN_EXTERNAL_SCOPE(b) ((b)->depth == 0 /*external_scope->depth*/)
00224 
00225 #define I_SYMBOL_BINDING(node) \
00226   (((struct lang_identifier *) IDENTIFIER_NODE_CHECK(node))->symbol_binding)
00227 #define I_SYMBOL_DECL(node) \
00228  (I_SYMBOL_BINDING(node) ? I_SYMBOL_BINDING(node)->decl : 0)
00229 
00230 #define I_TAG_BINDING(node) \
00231   (((struct lang_identifier *) IDENTIFIER_NODE_CHECK(node))->tag_binding)
00232 #define I_TAG_DECL(node) \
00233  (I_TAG_BINDING(node) ? I_TAG_BINDING(node)->decl : 0)
00234 
00235 #define I_LABEL_BINDING(node) \
00236   (((struct lang_identifier *) IDENTIFIER_NODE_CHECK(node))->label_binding)
00237 #define I_LABEL_DECL(node) \
00238  (I_LABEL_BINDING(node) ? I_LABEL_BINDING(node)->decl : 0)
00239 
00240 /* Each C symbol points to three linked lists of c_binding structures.
00241    These describe the values of the identifier in the three different
00242    namespaces defined by the language.  */
00243 
00244 struct lang_identifier GTY(())
00245 {
00246   struct c_common_identifier common_id;
00247   struct c_binding *symbol_binding; /* vars, funcs, constants, typedefs */
00248   struct c_binding *tag_binding;    /* struct/union/enum tags */
00249   struct c_binding *label_binding;  /* labels */
00250 };
00251 
00252 /* Validate c-lang.c's assumptions.  */
00253 extern char C_SIZEOF_STRUCT_LANG_IDENTIFIER_isnt_accurate
00254 [(sizeof(struct lang_identifier) == C_SIZEOF_STRUCT_LANG_IDENTIFIER) ? 1 : -1];
00255 
00256 /* The resulting tree type.  */
00257 
00258 union lang_tree_node
00259   GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
00260        chain_next ("TREE_CODE (&%h.generic) == INTEGER_TYPE ? (union lang_tree_node *) TYPE_NEXT_VARIANT (&%h.generic) : (union lang_tree_node *) TREE_CHAIN (&%h.generic)")))
00261 {
00262   union tree_node GTY ((tag ("0"),
00263       desc ("tree_node_structure (&%h)")))
00264     generic;
00265   struct lang_identifier GTY ((tag ("1"))) identifier;
00266 };
00267 
00268 /* Each c_scope structure describes the complete contents of one
00269    scope.  Four scopes are distinguished specially: the innermost or
00270    current scope, the innermost function scope, the file scope (always
00271    the second to outermost) and the outermost or external scope.
00272 
00273    Most declarations are recorded in the current scope.
00274 
00275    All normal label declarations are recorded in the innermost
00276    function scope, as are bindings of undeclared identifiers to
00277    error_mark_node.  (GCC permits nested functions as an extension,
00278    hence the 'innermost' qualifier.)  Explicitly declared labels
00279    (using the __label__ extension) appear in the current scope.
00280 
00281    Being in the file scope (current_scope == file_scope) causes
00282    special behavior in several places below.  Also, under some
00283    conditions the Objective-C front end records declarations in the
00284    file scope even though that isn't the current scope.
00285 
00286    All declarations with external linkage are recorded in the external
00287    scope, even if they aren't visible there; this models the fact that
00288    such declarations are visible to the entire program, and (with a
00289    bit of cleverness, see pushdecl) allows diagnosis of some violations
00290    of C99 6.2.2p7 and 6.2.7p2:
00291 
00292      If, within the same translation unit, the same identifier appears
00293      with both internal and external linkage, the behavior is
00294      undefined.
00295 
00296      All declarations that refer to the same object or function shall
00297      have compatible type; otherwise, the behavior is undefined.
00298 
00299    Initially only the built-in declarations, which describe compiler
00300    intrinsic functions plus a subset of the standard library, are in
00301    this scope.
00302 
00303    The order of the blocks list matters, and it is frequently appended
00304    to.  To avoid having to walk all the way to the end of the list on
00305    each insertion, or reverse the list later, we maintain a pointer to
00306    the last list entry.  (FIXME: It should be feasible to use a reversed
00307    list here.)
00308 
00309    The bindings list is strictly in reverse order of declarations;
00310    pop_scope relies on this.  */
00311 
00312 
00313 struct c_scope GTY((chain_next ("%h.outer")))
00314 {
00315   /* The scope containing this one.  */
00316   struct c_scope *outer;
00317 
00318   /* The next outermost function scope.  */
00319   struct c_scope *outer_function;
00320 
00321   /* All bindings in this scope.  */
00322   struct c_binding *bindings;
00323 
00324   /* For each scope (except the global one), a chain of BLOCK nodes
00325      for all the scopes that were entered and exited one level down.  */
00326   tree blocks;
00327   tree blocks_last;
00328 
00329   /* The depth of this scope.  Used to keep the ->shadowed chain of
00330      bindings sorted innermost to outermost.  */
00331   unsigned int depth : 28;
00332 
00333   /* True if we are currently filling this scope with parameter
00334      declarations.  */
00335   BOOL_BITFIELD parm_flag : 1;
00336 
00337   /* True if we already complained about forward parameter decls
00338      in this scope.  This prevents double warnings on
00339      foo (int a; int b; ...)  */
00340   BOOL_BITFIELD warned_forward_parm_decls : 1;
00341 
00342   /* True if this is the outermost block scope of a function body.
00343      This scope contains the parameters, the local variables declared
00344      in the outermost block, and all the labels (except those in
00345      nested functions, or declared at block scope with __label__).  */
00346   BOOL_BITFIELD function_body : 1;
00347 
00348   /* True means make a BLOCK for this scope no matter what.  */
00349   BOOL_BITFIELD keep : 1;
00350 };
00351 
00352 /* The scope currently in effect.  */
00353 
00354 static GTY(()) struct c_scope *current_scope;
00355 
00356 /* The innermost function scope.  Ordinary (not explicitly declared)
00357    labels, bindings to error_mark_node, and the lazily-created
00358    bindings of __func__ and its friends get this scope.  */
00359 
00360 static GTY(()) struct c_scope *current_function_scope;
00361 
00362 /* The C file scope.  This is reset for each input translation unit.  */
00363 
00364 static GTY(()) struct c_scope *file_scope;
00365 
00366 /* The outermost scope.  This is used for all declarations with
00367    external linkage, and only these, hence the name.  */
00368 
00369 static GTY(()) struct c_scope *external_scope;
00370 
00371 /* A chain of c_scope structures awaiting reuse.  */
00372 
00373 static GTY((deletable)) struct c_scope *scope_freelist;
00374 
00375 /* A chain of c_binding structures awaiting reuse.  */
00376 
00377 static GTY((deletable)) struct c_binding *binding_freelist;
00378 
00379 /* Append VAR to LIST in scope SCOPE.  */
00380 #define SCOPE_LIST_APPEND(scope, list, decl) do { \
00381   struct c_scope *s_ = (scope);       \
00382   tree d_ = (decl);         \
00383   if (s_->list##_last)          \
00384     TREE_CHAIN (s_->list##_last) = d_;      \
00385   else              \
00386     s_->list = d_;          \
00387   s_->list##_last = d_;         \
00388 } while (0)
00389 
00390 /* Concatenate FROM in scope FSCOPE onto TO in scope TSCOPE.  */
00391 #define SCOPE_LIST_CONCAT(tscope, to, fscope, from) do {  \
00392   struct c_scope *t_ = (tscope);        \
00393   struct c_scope *f_ = (fscope);        \
00394   if (t_->to##_last)            \
00395     TREE_CHAIN (t_->to##_last) = f_->from;      \
00396   else                \
00397     t_->to = f_->from;            \
00398   t_->to##_last = f_->from##_last;        \
00399 } while (0)
00400 
00401 /* True means unconditionally make a BLOCK for the next scope pushed.  */
00402 
00403 static bool keep_next_level_flag;
00404 
00405 /* True means the next call to push_scope will be the outermost scope
00406    of a function body, so do not push a new scope, merely cease
00407    expecting parameter decls.  */
00408 
00409 static bool next_is_function_body;
00410 
00411 /* Functions called automatically at the beginning and end of execution.  */
00412 
00413 static GTY(()) tree static_ctors;
00414 static GTY(()) tree static_dtors;
00415 
00416 /* Forward declarations.  */
00417 static tree lookup_name_in_scope (tree, struct c_scope *);
00418 static tree c_make_fname_decl (tree, int);
00419 static tree grokdeclarator (const struct c_declarator *,
00420           struct c_declspecs *,
00421           enum decl_context, bool, tree *);
00422 static tree grokparms (struct c_arg_info *, bool);
00423 static void layout_array_type (tree);
00424 
00425 /* States indicating how grokdeclarator() should handle declspecs marked
00426    with __attribute__((deprecated)).  An object declared as
00427    __attribute__((deprecated)) suppresses warnings of uses of other
00428    deprecated items.  */
00429 
00430 enum deprecated_states {
00431   DEPRECATED_NORMAL,
00432   DEPRECATED_SUPPRESS
00433 };
00434 
00435 static enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
00436 
00437 void
00438 c_print_identifier (FILE *file, tree node, int indent)
00439 {
00440   print_node (file, "symbol", I_SYMBOL_DECL (node), indent + 4);
00441   print_node (file, "tag", I_TAG_DECL (node), indent + 4);
00442   print_node (file, "label", I_LABEL_DECL (node), indent + 4);
00443   if (C_IS_RESERVED_WORD (node))
00444     {
00445       tree rid = ridpointers[C_RID_CODE (node)];
00446       indent_to (file, indent + 4);
00447       fprintf (file, "rid " HOST_PTR_PRINTF " \"%s\"",
00448          (void *) rid, IDENTIFIER_POINTER (rid));
00449     }
00450 }
00451 
00452 /* Establish a binding between NAME, an IDENTIFIER_NODE, and DECL,
00453    which may be any of several kinds of DECL or TYPE or error_mark_node,
00454    in the scope SCOPE.  */
00455 static void
00456 bind (tree name, tree decl, struct c_scope *scope, bool invisible, bool nested)
00457 {
00458   struct c_binding *b, **here;
00459 
00460   if (binding_freelist)
00461     {
00462       b = binding_freelist;
00463       binding_freelist = b->prev;
00464     }
00465   else
00466     b = GGC_NEW (struct c_binding);
00467 
00468   b->shadowed = 0;
00469   b->decl = decl;
00470   b->id = name;
00471   b->depth = scope->depth;
00472   b->invisible = invisible;
00473   b->nested = nested;
00474   b->inner_comp = 0;
00475 
00476   b->type = 0;
00477 
00478   b->prev = scope->bindings;
00479   scope->bindings = b;
00480 
00481   if (!name)
00482     return;
00483 
00484   switch (TREE_CODE (decl))
00485     {
00486     case LABEL_DECL:     here = &I_LABEL_BINDING (name);   break;
00487     case ENUMERAL_TYPE:
00488     case UNION_TYPE:
00489     case RECORD_TYPE:    here = &I_TAG_BINDING (name);     break;
00490     case VAR_DECL:
00491     case FUNCTION_DECL:
00492     case TYPE_DECL:
00493     case CONST_DECL:
00494     case PARM_DECL:
00495     case ERROR_MARK:     here = &I_SYMBOL_BINDING (name);  break;
00496 
00497     default:
00498       gcc_unreachable ();
00499     }
00500 
00501   /* Locate the appropriate place in the chain of shadowed decls
00502      to insert this binding.  Normally, scope == current_scope and
00503      this does nothing.  */
00504   while (*here && (*here)->depth > scope->depth)
00505     here = &(*here)->shadowed;
00506 
00507   b->shadowed = *here;
00508   *here = b;
00509 }
00510 
00511 /* Clear the binding structure B, stick it on the binding_freelist,
00512    and return the former value of b->prev.  This is used by pop_scope
00513    and get_parm_info to iterate destructively over all the bindings
00514    from a given scope.  */
00515 static struct c_binding *
00516 free_binding_and_advance (struct c_binding *b)
00517 {
00518   struct c_binding *prev = b->prev;
00519 
00520   memset (b, 0, sizeof (struct c_binding));
00521   b->prev = binding_freelist;
00522   binding_freelist = b;
00523 
00524   return prev;
00525 }
00526 
00527 
00528 /* Hook called at end of compilation to assume 1 elt
00529    for a file-scope tentative array defn that wasn't complete before.  */
00530 
00531 void
00532 c_finish_incomplete_decl (tree decl)
00533 {
00534   if (TREE_CODE (decl) == VAR_DECL)
00535     {
00536       tree type = TREE_TYPE (decl);
00537       if (type != error_mark_node
00538     && TREE_CODE (type) == ARRAY_TYPE
00539     && !DECL_EXTERNAL (decl)
00540     && TYPE_DOMAIN (type) == 0)
00541   {
00542     warning ("%Jarray %qD assumed to have one element", decl, decl);
00543 
00544     complete_array_type (&TREE_TYPE (decl), NULL_TREE, true);
00545 
00546     layout_decl (decl, 0);
00547   }
00548     }
00549 }
00550 
00551 /* The Objective-C front-end often needs to determine the current scope.  */
00552 
00553 void *
00554 objc_get_current_scope (void)
00555 {
00556   return current_scope;
00557 }
00558 
00559 /* The following function is used only by Objective-C.  It needs to live here
00560    because it accesses the innards of c_scope.  */
00561 
00562 void
00563 objc_mark_locals_volatile (void *enclosing_blk)
00564 {
00565   struct c_scope *scope;
00566   struct c_binding *b;
00567 
00568   for (scope = current_scope;
00569        scope && scope != enclosing_blk;
00570        scope = scope->outer)
00571     {
00572       for (b = scope->bindings; b; b = b->prev)
00573   {
00574     if (TREE_CODE (b->decl) == VAR_DECL
00575         || TREE_CODE (b->decl) == PARM_DECL)
00576       {
00577         C_DECL_REGISTER (b->decl) = 0;
00578         DECL_REGISTER (b->decl) = 0;
00579         TREE_THIS_VOLATILE (b->decl) = 1;
00580       }
00581   }
00582 
00583       /* Do not climb up past the current function.  */
00584       if (scope->function_body)
00585   break;
00586     }
00587 }
00588 
00589 /* Nonzero if we are currently in file scope.  */
00590 
00591 int
00592 global_bindings_p (void)
00593 {
00594   return current_scope == file_scope && !c_override_global_bindings_to_false;
00595 }
00596 
00597 void
00598 keep_next_level (void)
00599 {
00600   keep_next_level_flag = true;
00601 }
00602 
00603 /* Identify this scope as currently being filled with parameters.  */
00604 
00605 void
00606 declare_parm_level (void)
00607 {
00608   current_scope->parm_flag = true;
00609 }
00610 
00611 void
00612 push_scope (void)
00613 {
00614   if (next_is_function_body)
00615     {
00616       /* This is the transition from the parameters to the top level
00617    of the function body.  These are the same scope
00618    (C99 6.2.1p4,6) so we do not push another scope structure.
00619    next_is_function_body is set only by store_parm_decls, which
00620    in turn is called when and only when we are about to
00621    encounter the opening curly brace for the function body.
00622 
00623    The outermost block of a function always gets a BLOCK node,
00624    because the debugging output routines expect that each
00625    function has at least one BLOCK.  */
00626       current_scope->parm_flag         = false;
00627       current_scope->function_body     = true;
00628       current_scope->keep              = true;
00629       current_scope->outer_function    = current_function_scope;
00630       current_function_scope           = current_scope;
00631 
00632       keep_next_level_flag = false;
00633       next_is_function_body = false;
00634     }
00635   else
00636     {
00637       struct c_scope *scope;
00638       if (scope_freelist)
00639   {
00640     scope = scope_freelist;
00641     scope_freelist = scope->outer;
00642   }
00643       else
00644   scope = GGC_CNEW (struct c_scope);
00645 
00646       scope->keep          = keep_next_level_flag;
00647       scope->outer         = current_scope;
00648       scope->depth     = current_scope ? (current_scope->depth + 1) : 0;
00649 
00650       /* Check for scope depth overflow.  Unlikely (2^28 == 268,435,456) but
00651    possible.  */
00652       if (current_scope && scope->depth == 0)
00653   {
00654     scope->depth--;
00655     sorry ("GCC supports only %u nested scopes", scope->depth);
00656   }
00657 
00658       current_scope        = scope;
00659       keep_next_level_flag = false;
00660     }
00661 }
00662 
00663 /* Set the TYPE_CONTEXT of all of TYPE's variants to CONTEXT.  */
00664 
00665 static void
00666 set_type_context (tree type, tree context)
00667 {
00668   for (type = TYPE_MAIN_VARIANT (type); type;
00669        type = TYPE_NEXT_VARIANT (type))
00670     TYPE_CONTEXT (type) = context;
00671 }
00672 
00673 /* Exit a scope.  Restore the state of the identifier-decl mappings
00674    that were in effect when this scope was entered.  Return a BLOCK
00675    node containing all the DECLs in this scope that are of interest
00676    to debug info generation.  */
00677 
00678 tree
00679 pop_scope (void)
00680 {
00681   struct c_scope *scope = current_scope;
00682   tree block, context, p;
00683   struct c_binding *b;
00684 
00685   bool functionbody = scope->function_body;
00686   bool keep = functionbody || scope->keep || scope->bindings;
00687 
00688   c_end_vm_scope (scope->depth);
00689 
00690   /* If appropriate, create a BLOCK to record the decls for the life
00691      of this function.  */
00692   block = 0;
00693   if (keep)
00694     {
00695       block = make_node (BLOCK);
00696       BLOCK_SUBBLOCKS (block) = scope->blocks;
00697       TREE_USED (block) = 1;
00698 
00699       /* In each subblock, record that this is its superior.  */
00700       for (p = scope->blocks; p; p = TREE_CHAIN (p))
00701   BLOCK_SUPERCONTEXT (p) = block;
00702 
00703       BLOCK_VARS (block) = 0;
00704     }
00705 
00706   /* The TYPE_CONTEXTs for all of the tagged types belonging to this
00707      scope must be set so that they point to the appropriate
00708      construct, i.e.  either to the current FUNCTION_DECL node, or
00709      else to the BLOCK node we just constructed.
00710 
00711      Note that for tagged types whose scope is just the formal
00712      parameter list for some function type specification, we can't
00713      properly set their TYPE_CONTEXTs here, because we don't have a
00714      pointer to the appropriate FUNCTION_TYPE node readily available
00715      to us.  For those cases, the TYPE_CONTEXTs of the relevant tagged
00716      type nodes get set in `grokdeclarator' as soon as we have created
00717      the FUNCTION_TYPE node which will represent the "scope" for these
00718      "parameter list local" tagged types.  */
00719   if (scope->function_body)
00720     context = current_function_decl;
00721   else if (scope == file_scope)
00722     {
00723       tree file_decl = build_decl (TRANSLATION_UNIT_DECL, 0, 0);
00724       TREE_CHAIN (file_decl) = all_translation_units;
00725       all_translation_units = file_decl;
00726       context = file_decl;
00727     }
00728   else
00729     context = block;
00730 
00731   /* Clear all bindings in this scope.  */
00732   for (b = scope->bindings; b; b = free_binding_and_advance (b))
00733     {
00734       p = b->decl;
00735       switch (TREE_CODE (p))
00736   {
00737   case LABEL_DECL:
00738     /* Warnings for unused labels, errors for undefined labels.  */
00739     if (TREE_USED (p) && !DECL_INITIAL (p))
00740       {
00741         error ("%Jlabel %qD used but not defined", p, p);
00742         DECL_INITIAL (p) = error_mark_node;
00743       }
00744     else if (!TREE_USED (p) && warn_unused_label)
00745       {
00746         if (DECL_INITIAL (p))
00747     warning ("%Jlabel %qD defined but not used", p, p);
00748         else
00749     warning ("%Jlabel %qD declared but not defined", p, p);
00750       }
00751     /* Labels go in BLOCK_VARS.  */
00752     TREE_CHAIN (p) = BLOCK_VARS (block);
00753     BLOCK_VARS (block) = p;
00754     gcc_assert (I_LABEL_BINDING (b->id) == b);
00755     I_LABEL_BINDING (b->id) = b->shadowed;
00756     break;
00757 
00758   case ENUMERAL_TYPE:
00759   case UNION_TYPE:
00760   case RECORD_TYPE:
00761     set_type_context (p, context);
00762 
00763     /* Types may not have tag-names, in which case the type
00764        appears in the bindings list with b->id NULL.  */
00765     if (b->id)
00766       {
00767         gcc_assert (I_TAG_BINDING (b->id) == b);
00768         I_TAG_BINDING (b->id) = b->shadowed;
00769       }
00770       break;
00771 
00772   case FUNCTION_DECL:
00773     /* Propagate TREE_ADDRESSABLE from nested functions to their
00774        containing functions.  */
00775     if (!TREE_ASM_WRITTEN (p)
00776         && DECL_INITIAL (p) != 0
00777         && TREE_ADDRESSABLE (p)
00778         && DECL_ABSTRACT_ORIGIN (p) != 0
00779         && DECL_ABSTRACT_ORIGIN (p) != p)
00780       TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (p)) = 1;
00781     if (!DECL_EXTERNAL (p)
00782         && DECL_INITIAL (p) == 0)
00783       {
00784         error ("%Jnested function %qD declared but never defined", p, p);
00785         undef_nested_function = true;
00786       }
00787     goto common_symbol;
00788 
00789   case VAR_DECL:
00790     /* Warnings for unused variables.  */
00791     if (warn_unused_variable
00792         && !TREE_USED (p)
00793         && !DECL_IN_SYSTEM_HEADER (p)
00794         && DECL_NAME (p)
00795         && !DECL_ARTIFICIAL (p)
00796         && scope != file_scope
00797         && scope != external_scope) 
00798       warning ("%Junused variable %qD", p, p);
00799 
00800     if (b->inner_comp)
00801       {
00802         error ("%Jtype of array %qD completed incompatibly with"
00803          " implicit initialization", p, p);
00804       }
00805 
00806     /* Fall through.  */
00807   case TYPE_DECL:
00808   case CONST_DECL:
00809   common_symbol:
00810     /* All of these go in BLOCK_VARS, but only if this is the
00811        binding in the home scope.  */
00812     if (!b->nested)
00813       {
00814         TREE_CHAIN (p) = BLOCK_VARS (block);
00815         BLOCK_VARS (block) = p;
00816       }
00817     /* If this is the file scope, and we are processing more
00818        than one translation unit in this compilation, set
00819        DECL_CONTEXT of each decl to the TRANSLATION_UNIT_DECL.
00820        This makes same_translation_unit_p work, and causes
00821        static declarations to be given disambiguating suffixes.  */
00822     if (scope == file_scope && num_in_fnames > 1)
00823       {
00824         DECL_CONTEXT (p) = context;
00825         if (TREE_CODE (p) == TYPE_DECL)
00826     set_type_context (TREE_TYPE (p), context);
00827       }
00828 
00829     /* Fall through.  */
00830     /* Parameters go in DECL_ARGUMENTS, not BLOCK_VARS, and have
00831        already been put there by store_parm_decls.  Unused-
00832        parameter warnings are handled by function.c.
00833        error_mark_node obviously does not go in BLOCK_VARS and
00834        does not get unused-variable warnings.  */
00835   case PARM_DECL:
00836   case ERROR_MARK:
00837     /* It is possible for a decl not to have a name.  We get
00838        here with b->id NULL in this case.  */
00839     if (b->id)
00840       {
00841         gcc_assert (I_SYMBOL_BINDING (b->id) == b);
00842         I_SYMBOL_BINDING (b->id) = b->shadowed;
00843         if (b->shadowed && b->shadowed->type)
00844     TREE_TYPE (b->shadowed->decl) = b->shadowed->type;
00845       }
00846     break;
00847 
00848   default:
00849     gcc_unreachable ();
00850   }
00851     }
00852 
00853 
00854   /* Dispose of the block that we just made inside some higher level.  */
00855   if ((scope->function_body || scope == file_scope) && context)
00856     {
00857       DECL_INITIAL (context) = block;
00858       BLOCK_SUPERCONTEXT (block) = context;
00859     }
00860   else if (scope->outer)
00861     {
00862       if (block)
00863   SCOPE_LIST_APPEND (scope->outer, blocks, block);
00864       /* If we did not make a block for the scope just exited, any
00865    blocks made for inner scopes must be carried forward so they
00866    will later become subblocks of something else.  */
00867       else if (scope->blocks)
00868   SCOPE_LIST_CONCAT (scope->outer, blocks, scope, blocks);
00869     }
00870 
00871   /* Pop the current scope, and free the structure for reuse.  */
00872   current_scope = scope->outer;
00873   if (scope->function_body)
00874     current_function_scope = scope->outer_function;
00875 
00876   memset (scope, 0, sizeof (struct c_scope));
00877   scope->outer = scope_freelist;
00878   scope_freelist = scope;
00879 
00880   return block;
00881 }
00882 
00883 void
00884 push_file_scope (void)
00885 {
00886   tree decl;
00887 
00888   if (file_scope)
00889     return;
00890 
00891   push_scope ();
00892   file_scope = current_scope;
00893 
00894   start_fname_decls ();
00895 
00896   for (decl = visible_builtins; decl; decl = TREE_CHAIN (decl))
00897     bind (DECL_NAME (decl), decl, file_scope,
00898     /*invisible=*/false, /*nested=*/true);
00899 }
00900 
00901 void
00902 pop_file_scope (void)
00903 {
00904   /* In case there were missing closebraces, get us back to the global
00905      binding level.  */
00906   while (current_scope != file_scope)
00907     pop_scope ();
00908 
00909   /* __FUNCTION__ is defined at file scope ("").  This
00910      call may not be necessary as my tests indicate it
00911      still works without it.  */
00912   finish_fname_decls ();
00913 
00914   /* This is the point to write out a PCH if we're doing that.
00915      In that case we do not want to do anything else.  */
00916   if (pch_file)
00917     {
00918       c_common_write_pch ();
00919       return;
00920     }
00921 
00922   /* Pop off the file scope and close this translation unit.  */
00923   pop_scope ();
00924   file_scope = 0;
00925 
00926   maybe_apply_pending_pragma_weaks ();
00927   cgraph_finalize_compilation_unit ();
00928 }
00929 
00930 /* Insert BLOCK at the end of the list of subblocks of the current
00931    scope.  This is used when a BIND_EXPR is expanded, to handle the
00932    BLOCK node inside the BIND_EXPR.  */
00933 
00934 void
00935 insert_block (tree block)
00936 {
00937   TREE_USED (block) = 1;
00938   SCOPE_LIST_APPEND (current_scope, blocks, block);
00939 }
00940 
00941 /* Push a definition or a declaration of struct, union or enum tag "name".
00942    "type" should be the type node.
00943    We assume that the tag "name" is not already defined.
00944 
00945    Note that the definition may really be just a forward reference.
00946    In that case, the TYPE_SIZE will be zero.  */
00947 
00948 static void
00949 pushtag (tree name, tree type)
00950 {
00951   /* Record the identifier as the type's name if it has none.  */
00952   if (name && !TYPE_NAME (type))
00953     TYPE_NAME (type) = name;
00954   bind (name, type, current_scope, /*invisible=*/false, /*nested=*/false);
00955 
00956   /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the
00957      tagged type we just added to the current scope.  This fake
00958      NULL-named TYPE_DECL node helps dwarfout.c to know when it needs
00959      to output a representation of a tagged type, and it also gives
00960      us a convenient place to record the "scope start" address for the
00961      tagged type.  */
00962 
00963   TYPE_STUB_DECL (type) = pushdecl (build_decl (TYPE_DECL, NULL_TREE, type));
00964 
00965   /* An approximation for now, so we can tell this is a function-scope tag.
00966      This will be updated in pop_scope.  */
00967   TYPE_CONTEXT (type) = DECL_CONTEXT (TYPE_STUB_DECL (type));
00968 }
00969 
00970 /* Subroutine of compare_decls.  Allow harmless mismatches in return
00971    and argument types provided that the type modes match.  This function
00972    return a unified type given a suitable match, and 0 otherwise.  */
00973 
00974 static tree
00975 match_builtin_function_types (tree newtype, tree oldtype)
00976 {
00977   tree newrettype, oldrettype;
00978   tree newargs, oldargs;
00979   tree trytype, tryargs;
00980 
00981   /* Accept the return type of the new declaration if same modes.  */
00982   oldrettype = TREE_TYPE (oldtype);
00983   newrettype = TREE_TYPE (newtype);
00984 
00985   if (TYPE_MODE (oldrettype) != TYPE_MODE (newrettype))
00986     return 0;
00987 
00988   oldargs = TYPE_ARG_TYPES (oldtype);
00989   newargs = TYPE_ARG_TYPES (newtype);
00990   tryargs = newargs;
00991 
00992   while (oldargs || newargs)
00993     {
00994       if (!oldargs
00995     || !newargs
00996     || !TREE_VALUE (oldargs)
00997     || !TREE_VALUE (newargs)
00998     || TYPE_MODE (TREE_VALUE (oldargs))
00999        != TYPE_MODE (TREE_VALUE (newargs)))
01000   return 0;
01001 
01002       oldargs = TREE_CHAIN (oldargs);
01003       newargs = TREE_CHAIN (newargs);
01004     }
01005 
01006   trytype = build_function_type (newrettype, tryargs);
01007   return build_type_attribute_variant (trytype, TYPE_ATTRIBUTES (oldtype));
01008 }
01009 
01010 /* Subroutine of diagnose_mismatched_decls.  Check for function type
01011    mismatch involving an empty arglist vs a nonempty one and give clearer
01012    diagnostics.  */
01013 static void
01014 diagnose_arglist_conflict (tree newdecl, tree olddecl,
01015          tree newtype, tree oldtype)
01016 {
01017   tree t;
01018 
01019   if (TREE_CODE (olddecl) != FUNCTION_DECL
01020       || !comptypes (TREE_TYPE (oldtype), TREE_TYPE (newtype))
01021       || !((TYPE_ARG_TYPES (oldtype) == 0 && DECL_INITIAL (olddecl) == 0)
01022      ||
01023      (TYPE_ARG_TYPES (newtype) == 0 && DECL_INITIAL (newdecl) == 0)))
01024     return;
01025 
01026   t = TYPE_ARG_TYPES (oldtype);
01027   if (t == 0)
01028     t = TYPE_ARG_TYPES (newtype);
01029   for (; t; t = TREE_CHAIN (t))
01030     {
01031       tree type = TREE_VALUE (t);
01032 
01033       if (TREE_CHAIN (t) == 0
01034     && TYPE_MAIN_VARIANT (type) != void_type_node)
01035   {
01036     inform ("a parameter list with an ellipsis can%'t match "
01037       "an empty parameter name list declaration");
01038     break;
01039   }
01040 
01041       if (c_type_promotes_to (type) != type)
01042   {
01043     inform ("an argument type that has a default promotion can%'t match "
01044       "an empty parameter name list declaration");
01045     break;
01046   }
01047     }
01048 }
01049 
01050 /* Another subroutine of diagnose_mismatched_decls.  OLDDECL is an
01051    old-style function definition, NEWDECL is a prototype declaration.
01052    Diagnose inconsistencies in the argument list.  Returns TRUE if
01053    the prototype is compatible, FALSE if not.  */
01054 static bool
01055 validate_proto_after_old_defn (tree newdecl, tree newtype, tree oldtype)
01056 {
01057   tree newargs, oldargs;
01058   int i;
01059 
01060 #define END_OF_ARGLIST(t) ((t) == void_type_node)
01061 
01062   oldargs = TYPE_ACTUAL_ARG_TYPES (oldtype);
01063   newargs = TYPE_ARG_TYPES (newtype);
01064   i = 1;
01065 
01066   for (;;)
01067     {
01068       tree oldargtype = TYPE_MAIN_VARIANT (TREE_VALUE (oldargs));
01069       tree newargtype = TYPE_MAIN_VARIANT (TREE_VALUE (newargs));
01070 
01071       if (END_OF_ARGLIST (oldargtype) && END_OF_ARGLIST (newargtype))
01072   break;
01073 
01074       /* Reaching the end of just one list means the two decls don't
01075    agree on the number of arguments.  */
01076       if (END_OF_ARGLIST (oldargtype))
01077   {
01078     error ("%Jprototype for %qD declares more arguments "
01079      "than previous old-style definition", newdecl, newdecl);
01080     return false;
01081   }
01082       else if (END_OF_ARGLIST (newargtype))
01083   {
01084     error ("%Jprototype for %qD declares fewer arguments "
01085      "than previous old-style definition", newdecl, newdecl);
01086     return false;
01087   }
01088 
01089       /* Type for passing arg must be consistent with that declared
01090    for the arg.  */
01091       else if (!comptypes (oldargtype, newargtype))
01092   {
01093     error ("%Jprototype for %qD declares argument %d"
01094      " with incompatible type",
01095      newdecl, newdecl, i);
01096     return false;
01097   }
01098 
01099       oldargs = TREE_CHAIN (oldargs);
01100       newargs = TREE_CHAIN (newargs);
01101       i++;
01102     }
01103 
01104   /* If we get here, no errors were found, but do issue a warning
01105      for this poor-style construct.  */
01106   warning ("%Jprototype for %qD follows non-prototype definition",
01107      newdecl, newdecl);
01108   return true;
01109 #undef END_OF_ARGLIST
01110 }
01111 
01112 /* Subroutine of diagnose_mismatched_decls.  Report the location of DECL,
01113    first in a pair of mismatched declarations, using the diagnostic
01114    function DIAG.  */
01115 static void
01116 locate_old_decl (tree decl, void (*diag)(const char *, ...))
01117 {
01118   if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
01119     ;
01120   else if (DECL_INITIAL (decl))
01121     diag (G_("%Jprevious definition of %qD was here"), decl, decl);
01122   else if (C_DECL_IMPLICIT (decl))
01123     diag (G_("%Jprevious implicit declaration of %qD was here"), decl, decl);
01124   else
01125     diag (G_("%Jprevious declaration of %qD was here"), decl, decl);
01126 }
01127 
01128 /* Subroutine of duplicate_decls.  Compare NEWDECL to OLDDECL.
01129    Returns true if the caller should proceed to merge the two, false
01130    if OLDDECL should simply be discarded.  As a side effect, issues
01131    all necessary diagnostics for invalid or poor-style combinations.
01132    If it returns true, writes the types of NEWDECL and OLDDECL to
01133    *NEWTYPEP and *OLDTYPEP - these may have been adjusted from
01134    TREE_TYPE (NEWDECL, OLDDECL) respectively.  */
01135 
01136 static bool
01137 diagnose_mismatched_decls (tree newdecl, tree olddecl,
01138          tree *newtypep, tree *oldtypep)
01139 {
01140   tree newtype, oldtype;
01141   bool pedwarned = false;
01142   bool warned = false;
01143   bool retval = true;
01144 
01145   /* If we have error_mark_node for either decl or type, just discard
01146      the previous decl - we're in an error cascade already.  */
01147   if (olddecl == error_mark_node || newdecl == error_mark_node)
01148     return false;
01149   *oldtypep = oldtype = TREE_TYPE (olddecl);
01150   *newtypep = newtype = TREE_TYPE (newdecl);
01151   if (oldtype == error_mark_node || newtype == error_mark_node)
01152     return false;
01153 
01154   /* Two different categories of symbol altogether.  This is an error
01155      unless OLDDECL is a builtin.  OLDDECL will be discarded in any case.  */
01156   if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
01157     {
01158       if (!(TREE_CODE (olddecl) == FUNCTION_DECL
01159       && DECL_BUILT_IN (olddecl)
01160       && !C_DECL_DECLARED_BUILTIN (olddecl)))
01161   {
01162     error ("%J%qD redeclared as different kind of symbol",
01163      newdecl, newdecl);
01164     locate_old_decl (olddecl, error);
01165   }
01166       else if (TREE_PUBLIC (newdecl))
01167   warning ("%Jbuilt-in function %qD declared as non-function",
01168      newdecl, newdecl);
01169       else if (warn_shadow)
01170   warning ("%Jdeclaration of %qD shadows a built-in function",
01171      newdecl, newdecl);
01172       return false;
01173     }
01174 
01175   /* Enumerators have no linkage, so may only be declared once in a
01176      given scope.  */
01177   if (TREE_CODE (olddecl) == CONST_DECL)
01178     {
01179       error ("%Jredeclaration of enumerator %qD", newdecl, newdecl);
01180       locate_old_decl (olddecl, error);
01181       return false;
01182     }
01183 
01184   if (!comptypes (oldtype, newtype))
01185     {
01186       if (TREE_CODE (olddecl) == FUNCTION_DECL
01187     && DECL_BUILT_IN (olddecl) && !C_DECL_DECLARED_BUILTIN (olddecl))
01188   {
01189     /* Accept harmless mismatch in function types.
01190        This is for the ffs and fprintf builtins.  */
01191     tree trytype = match_builtin_function_types (newtype, oldtype);
01192 
01193     if (trytype && comptypes (newtype, trytype))
01194       *oldtypep = oldtype = trytype;
01195     else
01196       {
01197         /* If types don't match for a built-in, throw away the
01198      built-in.  No point in calling locate_old_decl here, it
01199      won't print anything.  */
01200         warning ("%Jconflicting types for built-in function %qD",
01201            newdecl, newdecl);
01202         return false;
01203       }
01204   }
01205       else if (TREE_CODE (olddecl) == FUNCTION_DECL
01206          && DECL_IS_BUILTIN (olddecl))
01207   {
01208     /* A conflicting function declaration for a predeclared
01209        function that isn't actually built in.  Objective C uses
01210        these.  The new declaration silently overrides everything
01211        but the volatility (i.e. noreturn) indication.  See also
01212        below.  FIXME: Make Objective C use normal builtins.  */
01213     TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
01214     return false;
01215   }
01216       /* Permit void foo (...) to match int foo (...) if the latter is
01217    the definition and implicit int was used.  See
01218    c-torture/compile/920625-2.c.  */
01219       else if (TREE_CODE (newdecl) == FUNCTION_DECL && DECL_INITIAL (newdecl)
01220          && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == void_type_node
01221          && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == integer_type_node
01222          && C_FUNCTION_IMPLICIT_INT (newdecl) && !DECL_INITIAL (olddecl))
01223   {
01224     pedwarn ("%Jconflicting types for %qD", newdecl, newdecl);
01225     /* Make sure we keep void as the return type.  */
01226     TREE_TYPE (newdecl) = *newtypep = newtype = oldtype;
01227     C_FUNCTION_IMPLICIT_INT (newdecl) = 0;
01228     pedwarned = true;
01229   }
01230       /* Permit void foo (...) to match an earlier call to foo (...) with
01231    no declared type (thus, implicitly int).  */
01232       else if (TREE_CODE (newdecl) == FUNCTION_DECL
01233          && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == void_type_node
01234          && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == integer_type_node
01235          && C_DECL_IMPLICIT (olddecl) && !DECL_INITIAL (olddecl))
01236   {
01237     pedwarn ("%Jconflicting types for %qD", newdecl, newdecl);
01238     /* Make sure we keep void as the return type.  */
01239     TREE_TYPE (olddecl) = *oldtypep = oldtype = newtype;
01240     pedwarned = true;
01241   }
01242       else
01243   {
01244     if (TYPE_QUALS (newtype) != TYPE_QUALS (oldtype))
01245       error ("%J conflicting type qualifiers for %qD", newdecl, newdecl);
01246     else
01247       error ("%Jconflicting types for %qD", newdecl, newdecl);
01248     diagnose_arglist_conflict (newdecl, olddecl, newtype, oldtype);
01249     locate_old_decl (olddecl, error);
01250     return false;
01251   }
01252     }
01253 
01254   /* Redeclaration of a type is a constraint violation (6.7.2.3p1),
01255      but silently ignore the redeclaration if either is in a system
01256      header.  (Conflicting redeclarations were handled above.)  */
01257   if (TREE_CODE (newdecl) == TYPE_DECL)
01258     {
01259       if (DECL_IN_SYSTEM_HEADER (newdecl) || DECL_IN_SYSTEM_HEADER (olddecl))
01260   return true;  /* Allow OLDDECL to continue in use.  */
01261 
01262       error ("%Jredefinition of typedef %qD", newdecl, newdecl);
01263       locate_old_decl (olddecl, error);
01264       return false;
01265     }
01266 
01267   /* Function declarations can either be 'static' or 'extern' (no
01268      qualifier is equivalent to 'extern' - C99 6.2.2p5) and therefore
01269      can never conflict with each other on account of linkage (6.2.2p4).
01270      Multiple definitions are not allowed (6.9p3,5) but GCC permits
01271      two definitions if one is 'extern inline' and one is not.  The non-
01272      extern-inline definition supersedes the extern-inline definition.  */
01273   else if (TREE_CODE (newdecl) == FUNCTION_DECL)
01274     {
01275       /* If you declare a built-in function name as static, or
01276    define the built-in with an old-style definition (so we
01277    can't validate the argument list) the built-in definition is
01278    overridden, but optionally warn this was a bad choice of name.  */
01279       if (DECL_BUILT_IN (olddecl)
01280     && !C_DECL_DECLARED_BUILTIN (olddecl)
01281     && (!TREE_PUBLIC (newdecl)
01282         || (DECL_INITIAL (newdecl)
01283       && !TYPE_ARG_TYPES (TREE_TYPE (newdecl)))))
01284   {
01285     if (warn_shadow)
01286       warning ("%Jdeclaration of %qD shadows a built-in function",
01287          newdecl, newdecl);
01288     /* Discard the old built-in function.  */
01289     return false;
01290   }
01291 
01292       if (DECL_INITIAL (newdecl))
01293   {
01294     if (DECL_INITIAL (olddecl))
01295       {
01296         /* If both decls have extern inline and are in the same TU,
01297            reject the new decl.  */
01298         if (DECL_DECLARED_INLINE_P (olddecl)
01299       && DECL_EXTERNAL (olddecl)
01300       && DECL_DECLARED_INLINE_P (newdecl)
01301       && DECL_EXTERNAL (newdecl)
01302       && same_translation_unit_p (newdecl, olddecl))
01303     {
01304       error ("%Jredefinition of %qD", newdecl, newdecl);
01305       locate_old_decl (olddecl, error);
01306       return false;
01307     }
01308         /* If both decls have not extern inline, reject the new decl.  */
01309         if (!DECL_DECLARED_INLINE_P (olddecl)
01310       && !DECL_EXTERNAL (olddecl)
01311       && !DECL_DECLARED_INLINE_P (newdecl)
01312       && !DECL_EXTERNAL (newdecl))
01313     {
01314       error ("%Jredefinition of %qD", newdecl, newdecl);
01315       locate_old_decl (olddecl, error);
01316       return false;
01317     }
01318         /* If the new decl is declared as extern inline, error if they are
01319            in the same TU, otherwise retain the old decl.  */
01320         if (!DECL_DECLARED_INLINE_P (olddecl)
01321       && !DECL_EXTERNAL (olddecl)
01322       && DECL_DECLARED_INLINE_P (newdecl)
01323       && DECL_EXTERNAL (newdecl))
01324     {
01325       if (same_translation_unit_p (newdecl, olddecl))
01326         {
01327           error ("%Jredefinition of %qD", newdecl, newdecl);
01328           locate_old_decl (olddecl, error);
01329           return false;
01330         }
01331       else
01332         retval = false;
01333     }
01334      }
01335   }
01336       /* If we have a prototype after an old-style function definition,
01337    the argument types must be checked specially.  */
01338       else if (DECL_INITIAL (olddecl)
01339          && !TYPE_ARG_TYPES (oldtype) && TYPE_ARG_TYPES (newtype)
01340          && TYPE_ACTUAL_ARG_TYPES (oldtype)
01341          && !validate_proto_after_old_defn (newdecl, newtype, oldtype))
01342   {
01343     locate_old_decl (olddecl, error);
01344     return false;
01345   }
01346       /* A non-static declaration (even an "extern") followed by a
01347    static declaration is undefined behavior per C99 6.2.2p3-5,7.
01348    The same is true for a static forward declaration at block
01349    scope followed by a non-static declaration/definition at file
01350    scope.  Static followed by non-static at the same scope is
01351    not undefined behavior, and is the most convenient way to get
01352    some effects (see e.g.  what unwind-dw2-fde-glibc.c does to
01353    the definition of _Unwind_Find_FDE in unwind-dw2-fde.c), but
01354    we do diagnose it if -Wtraditional.  */
01355       if (TREE_PUBLIC (olddecl) && !TREE_PUBLIC (newdecl))
01356   {
01357     /* Two exceptions to the rule.  If olddecl is an extern
01358        inline, or a predeclared function that isn't actually
01359        built in, newdecl silently overrides olddecl.  The latter
01360        occur only in Objective C; see also above.  (FIXME: Make
01361        Objective C use normal builtins.)  */
01362     if (!DECL_IS_BUILTIN (olddecl)
01363         && !(DECL_EXTERNAL (olddecl)
01364        && DECL_DECLARED_INLINE_P (olddecl)))
01365       {
01366         error ("%Jstatic declaration of %qD follows "
01367          "non-static declaration", newdecl, newdecl);
01368         locate_old_decl (olddecl, error);
01369       }
01370     return false;
01371   }
01372       else if (TREE_PUBLIC (newdecl) && !TREE_PUBLIC (olddecl))
01373   {
01374     if (DECL_CONTEXT (olddecl))
01375       {
01376         error ("%Jnon-static declaration of %qD follows "
01377          "static declaration", newdecl, newdecl);
01378         locate_old_decl (olddecl, error);
01379         return false;
01380       }
01381     else if (warn_traditional)
01382       {
01383         warning ("%Jnon-static declaration of %qD follows "
01384            "static declaration", newdecl, newdecl);
01385         warned = true;
01386       }
01387   }
01388     }
01389   else if (TREE_CODE (newdecl) == VAR_DECL)
01390     {
01391       /* Only variables can be thread-local, and all declarations must
01392    agree on this property.  */
01393       if (DECL_THREAD_LOCAL (newdecl) != DECL_THREAD_LOCAL (olddecl))
01394   {
01395     if (DECL_THREAD_LOCAL (newdecl))
01396       error ("%Jthread-local declaration of %qD follows "
01397        "non-thread-local declaration", newdecl, newdecl);
01398     else
01399       error ("%Jnon-thread-local declaration of %qD follows "
01400        "thread-local declaration", newdecl, newdecl);
01401 
01402     locate_old_decl (olddecl, error);
01403     return false;
01404   }
01405 
01406       /* Multiple initialized definitions are not allowed (6.9p3,5).  */
01407       if (DECL_INITIAL (newdecl) && DECL_INITIAL (olddecl))
01408   {
01409     error ("%Jredefinition of %qD", newdecl, newdecl);
01410     locate_old_decl (olddecl, error);
01411     return false;
01412   }
01413 
01414       /* Objects declared at file scope: if the first declaration had
01415    external linkage (even if it was an external reference) the
01416    second must have external linkage as well, or the behavior is
01417    undefined.  If the first declaration had internal linkage, then
01418    the second must too, or else be an external reference (in which
01419    case the composite declaration still has internal linkage).
01420    As for function declarations, we warn about the static-then-
01421    extern case only for -Wtraditional.  See generally 6.2.2p3-5,7.  */
01422       if (DECL_FILE_SCOPE_P (newdecl)
01423     && TREE_PUBLIC (newdecl) != TREE_PUBLIC (olddecl))
01424   {
01425     if (DECL_EXTERNAL (newdecl))
01426       {
01427         if (!DECL_FILE_SCOPE_P (olddecl))
01428     {
01429       error ("%Jextern declaration of %qD follows "
01430        "declaration with no linkage", newdecl, newdecl);
01431       locate_old_decl (olddecl, error);
01432       return false;
01433     }
01434         else if (warn_traditional)
01435     {
01436       warning ("%Jnon-static declaration of %qD follows "
01437          "static declaration", newdecl, newdecl);
01438       warned = true;
01439     }
01440       }
01441     else
01442       {
01443         if (TREE_PUBLIC (newdecl))
01444     error ("%Jnon-static declaration of %qD follows "
01445            "static declaration", newdecl, newdecl);
01446         else
01447     error ("%Jstatic declaration of %qD follows "
01448            "non-static declaration", newdecl, newdecl);
01449 
01450         locate_old_decl (olddecl, error);
01451         return false;
01452       }
01453   }
01454       /* Two objects with the same name declared at the same block
01455    scope must both be external references (6.7p3).  */
01456       else if (!DECL_FILE_SCOPE_P (newdecl))
01457   {
01458     if (DECL_EXTERNAL (newdecl))
01459       {
01460         /* Extern with initializer at block scope, which will
01461      already have received an error.  */
01462       }
01463     else if (DECL_EXTERNAL (olddecl))
01464       {
01465         error ("%Jdeclaration of %qD with no linkage follows "
01466          "extern declaration", newdecl, newdecl);
01467         locate_old_decl (olddecl, error);
01468       }
01469     else
01470       {
01471         error ("%Jredeclaration of %qD with no linkage",
01472          newdecl, newdecl);
01473         locate_old_decl (olddecl, error);
01474       }
01475 
01476     return false;
01477   }
01478     }
01479 
01480   /* warnings */
01481   /* All decls must agree on a visibility.  */
01482   if (DECL_VISIBILITY_SPECIFIED (newdecl) && DECL_VISIBILITY_SPECIFIED (olddecl)
01483       && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
01484     {
01485       warning ("%Jredeclaration of %qD with different visibility "
01486          "(old visibility preserved)", newdecl, newdecl);
01487       warned = true;
01488     }
01489 
01490   if (TREE_CODE (newdecl) == FUNCTION_DECL)
01491     {
01492       /* Diagnose inline __attribute__ ((noinline)) which is silly.  */
01493       if (DECL_DECLARED_INLINE_P (newdecl)
01494     && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
01495   {
01496     warning ("%Jinline declaration of %qD follows "
01497        "declaration with attribute noinline", newdecl, newdecl);
01498     warned = true;
01499   }
01500       else if (DECL_DECLARED_INLINE_P (olddecl)
01501          && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)))
01502   {
01503     warning ("%Jdeclaration of %qD with attribute noinline follows "
01504        "inline declaration ", newdecl, newdecl);
01505     warned = true;
01506   }
01507 
01508       /* Inline declaration after use or definition.
01509    ??? Should we still warn about this now we have unit-at-a-time
01510    mode and can get it right?
01511    Definitely don't complain if the decls are in different translation
01512    units.  */
01513       if (DECL_DECLARED_INLINE_P (newdecl) && !DECL_DECLARED_INLINE_P (olddecl)
01514     && same_translation_unit_p (olddecl, newdecl))
01515   {
01516     if (TREE_USED (olddecl))
01517       {
01518         warning ("%J%qD declared inline after being called",
01519            olddecl, olddecl);
01520         warned = true;
01521       }
01522     else if (DECL_INITIAL (olddecl))
01523       {
01524         warning ("%J%qD declared inline after its definition",
01525            olddecl, olddecl);
01526         warned = true;
01527       }
01528   }
01529     }
01530   else /* PARM_DECL, VAR_DECL */
01531     {
01532       /* Redeclaration of a parameter is a constraint violation (this is
01533    not explicitly stated, but follows from C99 6.7p3 [no more than
01534    one declaration of the same identifier with no linkage in the
01535    same scope, except type tags] and 6.2.2p6 [parameters have no
01536    linkage]).  We must check for a forward parameter declaration,
01537    indicated by TREE_ASM_WRITTEN on the old declaration - this is
01538    an extension, the mandatory diagnostic for which is handled by
01539    mark_forward_parm_decls.  */
01540 
01541       if (TREE_CODE (newdecl) == PARM_DECL
01542     && (!TREE_ASM_WRITTEN (olddecl) || TREE_ASM_WRITTEN (newdecl)))
01543   {
01544     error ("%Jredefinition of parameter %qD", newdecl, newdecl);
01545     locate_old_decl (olddecl, error);
01546     return false;
01547   }
01548     }
01549 
01550   /* Optional warning for completely redundant decls.  */
01551   if (!warned && !pedwarned
01552       && warn_redundant_decls
01553       /* Don't warn about a function declaration followed by a
01554    definition.  */
01555       && !(TREE_CODE (newdecl) == FUNCTION_DECL
01556      && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl))
01557       /* Don't warn about redundant redeclarations of builtins.  */
01558       && !(TREE_CODE (newdecl) == FUNCTION_DECL
01559      && !DECL_BUILT_IN (newdecl)
01560      && DECL_BUILT_IN (olddecl)
01561      && !C_DECL_DECLARED_BUILTIN (olddecl))
01562       /* Don't warn about an extern followed by a definition.  */
01563       && !(DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl))
01564       /* Don't warn about forward parameter decls.  */
01565       && !(TREE_CODE (newdecl) == PARM_DECL
01566      && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
01567       /* Don't warn about a variable definition following a declaration.  */
01568       && !(TREE_CODE (newdecl) == VAR_DECL
01569      && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl)))
01570     {
01571       warning ("%Jredundant redeclaration of %qD", newdecl, newdecl);
01572       warned = true;
01573     }
01574 
01575   /* Report location of previous decl/defn in a consistent manner.  */
01576   if (warned || pedwarned)
01577     locate_old_decl (olddecl, pedwarned ? pedwarn : warning);
01578 
01579   return retval;
01580 }
01581 
01582 /* Subroutine of duplicate_decls.  NEWDECL has been found to be
01583    consistent with OLDDECL, but carries new information.  Merge the
01584    new information into OLDDECL.  This function issues no
01585    diagnostics.  */
01586 
01587 static void
01588 merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
01589 {
01590   int new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL
01591          && DECL_INITIAL (newdecl) != 0);
01592   int new_is_prototype = (TREE_CODE (newdecl) == FUNCTION_DECL
01593         && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != 0);
01594   int old_is_prototype = (TREE_CODE (olddecl) == FUNCTION_DECL
01595         && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) != 0);
01596 
01597   /* For real parm decl following a forward decl, rechain the old decl
01598      in its new location and clear TREE_ASM_WRITTEN (it's not a
01599      forward decl anymore).  */
01600   if (TREE_CODE (newdecl) == PARM_DECL
01601       && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
01602     {
01603       struct c_binding *b, **here;
01604 
01605       for (here = &current_scope->bindings; *here; here = &(*here)->prev)
01606   if ((*here)->decl == olddecl)
01607     goto found;
01608       gcc_unreachable ();
01609 
01610     found:
01611       b = *here;
01612       *here = b->prev;
01613       b->prev = current_scope->bindings;
01614       current_scope->bindings = b;
01615 
01616       TREE_ASM_WRITTEN (olddecl) = 0;
01617     }
01618 
01619   DECL_ATTRIBUTES (newdecl)
01620     = targetm.merge_decl_attributes (olddecl, newdecl);
01621 
01622   /* Merge the data types specified in the two decls.  */
01623   TREE_TYPE (newdecl)
01624     = TREE_TYPE (olddecl)
01625     = composite_type (newtype, oldtype);
01626 
01627   /* Lay the type out, unless already done.  */
01628   if (!comptypes (oldtype, TREE_TYPE (newdecl)))
01629     {
01630       if (TREE_TYPE (newdecl) != error_mark_node)
01631   layout_type (TREE_TYPE (newdecl));
01632       if (TREE_CODE (newdecl) != FUNCTION_DECL
01633     && TREE_CODE (newdecl) != TYPE_DECL
01634     && TREE_CODE (newdecl) != CONST_DECL)
01635   layout_decl (newdecl, 0);
01636     }
01637   else
01638     {
01639       /* Since the type is OLDDECL's, make OLDDECL's size go with.  */
01640       DECL_SIZE (newdecl) = DECL_SIZE (olddecl);
01641       DECL_SIZE_UNIT (newdecl) = DECL_SIZE_UNIT (olddecl);
01642       DECL_MODE (newdecl) = DECL_MODE (olddecl);
01643       if (TREE_CODE (olddecl) != FUNCTION_DECL)
01644   if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
01645     {
01646       DECL_ALIGN (newdecl) = DECL_ALIGN (olddecl);
01647       DECL_USER_ALIGN (newdecl) |= DECL_ALIGN (olddecl);
01648     }
01649     }
01650 
01651   /* Keep the old rtl since we can safely use it.  */
01652   COPY_DECL_RTL (olddecl, newdecl);
01653 
01654   /* Merge the type qualifiers.  */
01655   if (TREE_READONLY (newdecl))
01656     TREE_READONLY (olddecl) = 1;
01657 
01658   if (TREE_THIS_VOLATILE (newdecl))
01659     {
01660       TREE_THIS_VOLATILE (olddecl) = 1;
01661       if (TREE_CODE (newdecl) == VAR_DECL)
01662   make_var_volatile (newdecl);
01663     }
01664 
01665   /* Merge deprecatedness.  */
01666   if (TREE_DEPRECATED (newdecl))
01667     TREE_DEPRECATED (olddecl) = 1;
01668 
01669   /* Keep source location of definition rather than declaration and of
01670      prototype rather than non-prototype unless that prototype is
01671      built-in.  */
01672   if ((DECL_INITIAL (newdecl) == 0 && DECL_INITIAL (olddecl) != 0)
01673       || (old_is_prototype && !new_is_prototype
01674     && !C_DECL_BUILTIN_PROTOTYPE (olddecl)))
01675     DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
01676 
01677   /* Merge the unused-warning information.  */
01678   if (DECL_IN_SYSTEM_HEADER (olddecl))
01679     DECL_IN_SYSTEM_HEADER (newdecl) = 1;
01680   else if (DECL_IN_SYSTEM_HEADER (newdecl))
01681     DECL_IN_SYSTEM_HEADER (olddecl) = 1;
01682 
01683   /* Merge the initialization information.  */
01684    if (DECL_INITIAL (newdecl) == 0)
01685     DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
01686 
01687   /* Merge the section attribute.
01688      We want to issue an error if the sections conflict but that must be
01689      done later in decl_attributes since we are called before attributes
01690      are assigned.  */
01691   if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
01692     DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
01693 
01694   /* Copy the assembler name.
01695      Currently, it can only be defined in the prototype.  */
01696   COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
01697 
01698   /* Use visibility of whichever declaration had it specified */
01699   if (DECL_VISIBILITY_SPECIFIED (olddecl))
01700     {
01701       DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
01702       DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
01703     }
01704 
01705   if (TREE_CODE (newdecl) == FUNCTION_DECL)
01706     {
01707       DECL_STATIC_CONSTRUCTOR(newdecl) |= DECL_STATIC_CONSTRUCTOR(olddecl);
01708       DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
01709       DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
01710       DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
01711   |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
01712       TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
01713       TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
01714       DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
01715       DECL_IS_PURE (newdecl) |= DECL_IS_PURE (olddecl);
01716     }
01717 
01718   /* Merge the storage class information.  */
01719   merge_weak (newdecl, olddecl);
01720 
01721   /* For functions, static overrides non-static.  */
01722   if (TREE_CODE (newdecl) == FUNCTION_DECL)
01723     {
01724       TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl);
01725       /* This is since we don't automatically
01726    copy the attributes of NEWDECL into OLDDECL.  */
01727       TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
01728       /* If this clears `static', clear it in the identifier too.  */
01729       if (!TREE_PUBLIC (olddecl))
01730   TREE_PUBLIC (DECL_NAME (olddecl)) = 0;
01731     }
01732   if (DECL_EXTERNAL (newdecl))
01733     {
01734       TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
01735       DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl);
01736 
01737       /* An extern decl does not override previous storage class.  */
01738       TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
01739       if (!DECL_EXTERNAL (newdecl))
01740   {
01741     DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
01742     DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
01743   }
01744     }
01745   else
01746     {
01747       TREE_STATIC (olddecl) = TREE_STATIC (newdecl);
01748       TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
01749     }
01750 
01751   if (TREE_CODE (newdecl) == FUNCTION_DECL)
01752     {
01753       /* If we're redefining a function previously defined as extern
01754    inline, make sure we emit debug info for the inline before we
01755    throw it away, in case it was inlined into a function that hasn't
01756    been written out yet.  */
01757       if (new_is_definition && DECL_INITIAL (olddecl))
01758   {
01759     if (TREE_USED (olddecl)
01760         /* In unit-at-a-time mode we never inline re-defined extern
01761            inline functions.  */
01762         && !flag_unit_at_a_time
01763         && cgraph_function_possibly_inlined_p (olddecl))
01764       (*debug_hooks->outlining_inline_function) (olddecl);
01765 
01766     /* The new defn must not be inline.  */
01767     DECL_INLINE (newdecl) = 0;
01768     DECL_UNINLINABLE (newdecl) = 1;
01769   }
01770       else
01771   {
01772     /* If either decl says `inline', this fn is inline,
01773        unless its definition was passed already.  */
01774     if (DECL_DECLARED_INLINE_P (newdecl)
01775         || DECL_DECLARED_INLINE_P (olddecl))
01776       DECL_DECLARED_INLINE_P (newdecl) = 1;
01777 
01778     DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
01779       = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
01780   }
01781 
01782       if (DECL_BUILT_IN (olddecl))
01783   {
01784     /* If redeclaring a builtin function, it stays built in.
01785        But it gets tagged as having been declared.  */
01786     DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl);
01787     DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
01788     C_DECL_DECLARED_BUILTIN (newdecl) = 1;
01789     if (new_is_prototype)
01790       C_DECL_BUILTIN_PROTOTYPE (newdecl) = 0;
01791     else
01792       C_DECL_BUILTIN_PROTOTYPE (newdecl)
01793         = C_DECL_BUILTIN_PROTOTYPE (olddecl);
01794   }
01795 
01796       /* Also preserve various other info from the definition.  */
01797       if (!new_is_definition)
01798   {
01799     DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
01800     DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
01801     DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
01802     DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
01803     DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
01804 
01805     /* Set DECL_INLINE on the declaration if we've got a body
01806        from which to instantiate.  */
01807     if (DECL_INLINE (olddecl) && !DECL_UNINLINABLE (newdecl))
01808       {
01809         DECL_INLINE (newdecl) = 1;
01810         DECL_ABSTRACT_ORIGIN (newdecl)
01811     = DECL_ABSTRACT_ORIGIN (olddecl);
01812       }
01813   }
01814       else
01815   {
01816     /* If a previous declaration said inline, mark the
01817        definition as inlinable.  */
01818     if (DECL_DECLARED_INLINE_P (newdecl)
01819         && !DECL_UNINLINABLE (newdecl))
01820       DECL_INLINE (newdecl) = 1;
01821   }
01822     }
01823 
01824   /* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
01825      But preserve OLDDECL's DECL_UID and DECL_CONTEXT.  */
01826   {
01827     unsigned olddecl_uid = DECL_UID (olddecl);
01828     tree olddecl_context = DECL_CONTEXT (olddecl);
01829 
01830     memcpy ((char *) olddecl + sizeof (struct tree_common),
01831       (char *) newdecl + sizeof (struct tree_common),
01832       sizeof (struct tree_decl) - sizeof (struct tree_common));
01833     DECL_UID (olddecl) = olddecl_uid;
01834     DECL_CONTEXT (olddecl) = olddecl_context;
01835   }
01836 
01837   /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
01838      so that encode_section_info has a chance to look at the new decl
01839      flags and attributes.  */
01840   if (DECL_RTL_SET_P (olddecl)
01841       && (TREE_CODE (olddecl) == FUNCTION_DECL
01842     || (TREE_CODE (olddecl) == VAR_DECL
01843         && TREE_STATIC (olddecl))))
01844     make_decl_rtl (olddecl);
01845 }
01846 
01847 /* Handle when a new declaration NEWDECL has the same name as an old
01848    one OLDDECL in the same binding contour.  Prints an error message
01849    if appropriate.
01850 
01851    If safely possible, alter OLDDECL to look like NEWDECL, and return
01852    true.  Otherwise, return false.  */
01853 
01854 static bool
01855 duplicate_decls (tree newdecl, tree olddecl)
01856 {
01857   tree newtype = NULL, oldtype = NULL;
01858 
01859   if (!diagnose_mismatched_decls (newdecl, olddecl, &newtype, &oldtype))
01860     return false;
01861 
01862   merge_decls (newdecl, olddecl, newtype, oldtype);
01863   return true;
01864 }
01865 
01866 
01867 /* Check whether decl-node NEW_DECL shadows an existing declaration.  */
01868 static void
01869 warn_if_shadowing (tree new_decl)
01870 {
01871   struct c_binding *b;
01872 
01873   /* Shadow warnings wanted?  */
01874   if (!warn_shadow
01875       /* No shadow warnings for internally generated vars.  */
01876       || DECL_IS_BUILTIN (new_decl)
01877       /* No shadow warnings for vars made for inlining.  */
01878       || DECL_FROM_INLINE (new_decl)
01879       /* Don't warn about the parm names in function declarator
01880    within a function declarator.  It would be nice to avoid
01881    warning in any function declarator in a declaration, as
01882    opposed to a definition, but there is no way to tell
01883    it's not a definition at this point.  */
01884       || (TREE_CODE (new_decl) == PARM_DECL && current_scope->outer->parm_flag))
01885     return;
01886 
01887   /* Is anything being shadowed?  Invisible decls do not count.  */
01888   for (b = I_SYMBOL_BINDING (DECL_NAME (new_decl)); b; b = b->shadowed)
01889     if (b->decl && b->decl != new_decl && !b->invisible)
01890       {
01891   tree old_decl = b->decl;
01892 
01893   if (old_decl == error_mark_node)
01894     {
01895       warning ("%Jdeclaration of %qD shadows previous non-variable",
01896          new_decl, new_decl);
01897       break;
01898     }
01899   else if (TREE_CODE (old_decl) == PARM_DECL)
01900     warning ("%Jdeclaration of %qD shadows a parameter",
01901        new_decl, new_decl);
01902   else if (DECL_FILE_SCOPE_P (old_decl))
01903     warning ("%Jdeclaration of %qD shadows a global declaration",
01904        new_decl, new_decl);
01905   else if (TREE_CODE (old_decl) == FUNCTION_DECL
01906      && DECL_BUILT_IN (old_decl))
01907     {
01908       warning ("%Jdeclaration of %qD shadows a built-in function",
01909          new_decl, new_decl);
01910       break;
01911     }
01912   else
01913     warning ("%Jdeclaration of %qD shadows a previous local",
01914        new_decl, new_decl);
01915 
01916   warning ("%Jshadowed declaration is here", old_decl);
01917 
01918   break;
01919       }
01920 }
01921 
01922 
01923 /* Subroutine of pushdecl.
01924 
01925    X is a TYPE_DECL for a typedef statement.  Create a brand new
01926    ..._TYPE node (which will be just a variant of the existing
01927    ..._TYPE node with identical properties) and then install X
01928    as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
01929 
01930    The whole point here is to end up with a situation where each
01931    and every ..._TYPE node the compiler creates will be uniquely
01932    associated with AT MOST one node representing a typedef name.
01933    This way, even though the compiler substitutes corresponding
01934    ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
01935    early on, later parts of the compiler can always do the reverse
01936    translation and get back the corresponding typedef name.  For
01937    example, given:
01938 
01939         typedef struct S MY_TYPE;
01940   MY_TYPE object;
01941 
01942    Later parts of the compiler might only know that `object' was of
01943    type `struct S' if it were not for code just below.  With this
01944    code however, later parts of the compiler see something like:
01945 
01946   struct S' == struct S
01947   typedef struct S' MY_TYPE;
01948   struct S' object;
01949 
01950     And they can then deduce (from the node for type struct S') that
01951     the original object declaration was:
01952 
01953     MY_TYPE object;
01954 
01955     Being able to do this is important for proper support of protoize,
01956     and also for generating precise symbolic debugging information
01957     which takes full account of the programmer's (typedef) vocabulary.
01958 
01959     Obviously, we don't want to generate a duplicate ..._TYPE node if
01960     the TYPE_DECL node that we are now processing really represents a
01961     standard built-in type.
01962 
01963     Since all standard types are effectively declared at line zero
01964     in the source file, we can easily check to see if we are working
01965     on a standard type by checking the current value of lineno.  */
01966 
01967 static void
01968 clone_underlying_type (tree x)
01969 {
01970   if (DECL_IS_BUILTIN (x))
01971     {
01972       if (TYPE_NAME (TREE_TYPE (x)) == 0)
01973   TYPE_NAME (TREE_TYPE (x)) = x;
01974     }
01975   else if (TREE_TYPE (x) != error_mark_node
01976      && DECL_ORIGINAL_TYPE (x) == NULL_TREE)
01977     {
01978       tree tt = TREE_TYPE (x);
01979       DECL_ORIGINAL_TYPE (x) = tt;
01980       tt = build_variant_type_copy (tt);
01981       TYPE_NAME (tt) = x;
01982       TREE_USED (tt) = TREE_USED (x);
01983       TREE_TYPE (x) = tt;
01984     }
01985 }
01986 
01987 /* Record a decl-node X as belonging to the current lexical scope.
01988    Check for errors (such as an incompatible declaration for the same
01989    name already seen in the same scope).
01990 
01991    Returns either X or an old decl for the same name.
01992    If an old decl is returned, it may have been smashed
01993    to agree with what X says.  */
01994 
01995 tree
01996 pushdecl (tree x)
01997 {
01998   tree name = DECL_NAME (x);
01999   struct c_scope *scope = current_scope;
02000   struct c_binding *b;
02001   bool nested = false;
02002 
02003   /* Functions need the lang_decl data.  */
02004   if (TREE_CODE (x) == FUNCTION_DECL && !DECL_LANG_SPECIFIC (x))
02005     DECL_LANG_SPECIFIC (x) = GGC_CNEW (struct lang_decl);
02006 
02007   /* Must set DECL_CONTEXT for everything not at file scope or
02008      DECL_FILE_SCOPE_P won't work.  Local externs don't count
02009      unless they have initializers (which generate code).  */
02010   if (current_function_decl
02011       && ((TREE_CODE (x) != FUNCTION_DECL && TREE_CODE (x) != VAR_DECL)
02012     || DECL_INITIAL (x) || !DECL_EXTERNAL (x)))
02013     DECL_CONTEXT (x) = current_function_decl;
02014 
02015   /* If this is of variably modified type, prevent jumping into its
02016      scope.  */
02017   if ((TREE_CODE (x) == VAR_DECL || TREE_CODE (x) == TYPE_DECL)
02018       && variably_modified_type_p (TREE_TYPE (x), NULL_TREE))
02019     c_begin_vm_scope (scope->depth);
02020 
02021   /* Anonymous decls are just inserted in the scope.  */
02022   if (!name)
02023     {
02024       bind (name, x, scope, /*invisible=*/false, /*nested=*/false);
02025       return x;
02026     }
02027 
02028   /* First, see if there is another declaration with the same name in
02029      the current scope.  If there is, duplicate_decls may do all the
02030      work for us.  If duplicate_decls returns false, that indicates
02031      two incompatible decls in the same scope; we are to silently
02032      replace the old one (duplicate_decls has issued all appropriate
02033      diagnostics).  In particular, we should not consider possible
02034      duplicates in the external scope, or shadowing.  */
02035   b = I_SYMBOL_BINDING (name);
02036   if (b && B_IN_SCOPE (b, scope))
02037     {
02038       struct c_binding *b_ext, *b_use;
02039       tree type = TREE_TYPE (x);
02040       tree visdecl = b->decl;
02041       tree vistype = TREE_TYPE (visdecl);
02042       if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
02043     && COMPLETE_TYPE_P (TREE_TYPE (x)))
02044   b->inner_comp = false;
02045       b_use = b;
02046       b_ext = b;
02047       /* If this is an external linkage declaration, we should check
02048    for compatibility with the type in the external scope before
02049    setting the type at this scope based on the visible
02050    information only.  */
02051       if (TREE_PUBLIC (x) && TREE_PUBLIC (visdecl))
02052   {
02053     while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext))
02054       b_ext = b_ext->shadowed;
02055     if (b_ext)
02056       {
02057         b_use = b_ext;
02058         if (b_use->type)
02059     TREE_TYPE (b_use->decl) = b_use->type;
02060       }
02061   }
02062       if (duplicate_decls (x, b_use->decl))
02063   {
02064     if (b_use != b)
02065       {
02066         /* Save the updated type in the external scope and
02067      restore the proper type for this scope.  */
02068         tree thistype;
02069         if (comptypes (vistype, type))
02070     thistype = composite_type (vistype, type);
02071         else
02072     thistype = TREE_TYPE (b_use->decl);
02073         b_use->type = TREE_TYPE (b_use->decl);
02074         if (TREE_CODE (b_use->decl) == FUNCTION_DECL
02075       && DECL_BUILT_IN (b_use->decl))
02076     thistype
02077       = build_type_attribute_variant (thistype,
02078               TYPE_ATTRIBUTES
02079               (b_use->type));
02080         TREE_TYPE (b_use->decl) = thistype;
02081       }
02082     return b_use->decl;
02083   }
02084       else
02085   goto skip_external_and_shadow_checks;
02086     }
02087 
02088   /* All declarations with external linkage, and all external
02089      references, go in the external scope, no matter what scope is
02090      current.  However, the binding in that scope is ignored for
02091      purposes of normal name lookup.  A separate binding structure is
02092      created in the requested scope; this governs the normal
02093      visibility of the symbol.
02094 
02095      The binding in the externals scope is used exclusively for
02096      detecting duplicate declarations of the same object, no matter
02097      what scope they are in; this is what we do here.  (C99 6.2.7p2:
02098      All declarations that refer to the same object or function shall
02099      have compatible type; otherwise, the behavior is undefined.)  */
02100   if (DECL_EXTERNAL (x) || scope == file_scope)
02101     {
02102       tree type = TREE_TYPE (x);
02103       tree vistype = 0;
02104       tree visdecl = 0;
02105       bool type_saved = false;
02106       if (b && !B_IN_EXTERNAL_SCOPE (b)
02107     && (TREE_CODE (b->decl) == FUNCTION_DECL
02108         || TREE_CODE (b->decl) == VAR_DECL)
02109     && DECL_FILE_SCOPE_P (b->decl))
02110   {
02111     visdecl = b->decl;
02112     vistype = TREE_TYPE (visdecl);
02113   }
02114       if (warn_nested_externs
02115     && scope != file_scope
02116     && !DECL_IN_SYSTEM_HEADER (x))
02117   warning ("nested extern declaration of %qD", x);
02118 
02119       while (b && !B_IN_EXTERNAL_SCOPE (b))
02120   {
02121     /* If this decl might be modified, save its type.  This is
02122        done here rather than when the decl is first bound
02123        because the type may change after first binding, through
02124        being completed or through attributes being added.  If we
02125        encounter multiple such decls, only the first should have
02126        its type saved; the others will already have had their
02127        proper types saved and the types will not have changed as
02128        their scopes will not have been re-entered.  */
02129     if (DECL_P (b->decl) && DECL_FILE_SCOPE_P (b->decl) && !type_saved)
02130       {
02131         b->type = TREE_TYPE (b->decl);
02132         type_saved = true;
02133       }
02134     if (B_IN_FILE_SCOPE (b)
02135         && TREE_CODE (b->decl) == VAR_DECL
02136         && TREE_STATIC (b->decl)
02137         && TREE_CODE (TREE_TYPE (b->decl)) == ARRAY_TYPE
02138         && !TYPE_DOMAIN (TREE_TYPE (b->decl))
02139         && TREE_CODE (type) == ARRAY_TYPE
02140         && TYPE_DOMAIN (type)
02141         && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
02142         && !integer_zerop (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
02143       {
02144         /* Array type completed in inner scope, which should be
02145      diagnosed if the completion does not have size 1 and
02146      it does not get completed in the file scope.  */
02147         b->inner_comp = true;
02148       }
02149     b = b->shadowed;
02150   }
02151 
02152       /* If a matching external declaration has been found, set its
02153    type to the composite of all the types of that declaration.
02154    After the consistency checks, it will be reset to the
02155    composite of the visible types only.  */
02156       if (b && (TREE_PUBLIC (x) || same_translation_unit_p (x, b->decl))
02157     && b->type)
02158   TREE_TYPE (b->decl) = b->type;
02159 
02160       /* The point of the same_translation_unit_p check here is,
02161    we want to detect a duplicate decl for a construct like
02162    foo() { extern bar(); } ... static bar();  but not if
02163    they are in different translation units.  In any case,
02164    the static does not go in the externals scope.  */
02165       if (b
02166     && (TREE_PUBLIC (x) || same_translation_unit_p (x, b->decl))
02167     && duplicate_decls (x, b->decl))
02168   {
02169     tree thistype;
02170     if (vistype)
02171       {
02172         if (comptypes (vistype, type))
02173     thistype = composite_type (vistype, type);
02174         else
02175     thistype = TREE_TYPE (b->decl);
02176       }
02177     else
02178       thistype = type;
02179     b->type = TREE_TYPE (b->decl);
02180     if (TREE_CODE (b->decl) == FUNCTION_DECL && DECL_BUILT_IN (b->decl))
02181       thistype
02182         = build_type_attribute_variant (thistype,
02183                 TYPE_ATTRIBUTES (b->type));
02184     TREE_TYPE (b->decl) = thistype;
02185     bind (name, b->decl, scope, /*invisible=*/false, /*nested=*/true);
02186     return b->decl;
02187   }
02188       else if (TREE_PUBLIC (x))
02189   {
02190     if (visdecl && !b && duplicate_decls (x, visdecl))
02191       {
02192         /* An external declaration at block scope referring to a
02193      visible entity with internal linkage.  The composite
02194      type will already be correct for this scope, so we
02195      just need to fall through to make the declaration in
02196      this scope.  */
02197         nested = true;
02198         x = visdecl;
02199       }
02200     else
02201       {
02202         bind (name, x, external_scope, /*invisible=*/true,
02203         /*nested=*/false);
02204         nested = true;
02205       }
02206   }
02207     }
02208 
02209   warn_if_shadowing (x);
02210 
02211  skip_external_and_shadow_checks:
02212   if (TREE_CODE (x) == TYPE_DECL)
02213     clone_underlying_type (x);
02214 
02215   bind (name, x, scope, /*invisible=*/false, nested);
02216 
02217   /* If x's type is incomplete because it's based on a
02218      structure or union which has not yet been fully declared,
02219      attach it to that structure or union type, so we can go
02220      back and complete the variable declaration later, if the
02221      structure or union gets fully declared.
02222 
02223      If the input is erroneous, we can have error_mark in the type
02224      slot (e.g. "f(void a, ...)") - that doesn't count as an
02225      incomplete type.  */
02226   if (TREE_TYPE (x) != error_mark_node
02227       && !COMPLETE_TYPE_P (TREE_TYPE (x)))
02228     {
02229       tree element = TREE_TYPE (x);
02230 
02231       while (TREE_CODE (element) == ARRAY_TYPE)
02232   element = TREE_TYPE (element);
02233       element = TYPE_MAIN_VARIANT (element);
02234 
02235       if ((TREE_CODE (element) == RECORD_TYPE
02236      || TREE_CODE (element) == UNION_TYPE)
02237     && (TREE_CODE (x) != TYPE_DECL
02238         || TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE)
02239     && !COMPLETE_TYPE_P (element))
02240   C_TYPE_INCOMPLETE_VARS (element)
02241     = tree_cons (NULL_TREE, x, C_TYPE_INCOMPLETE_VARS (element));
02242     }
02243   return x;
02244 }
02245 
02246 /* Record X as belonging to file scope.
02247    This is used only internally by the Objective-C front end,
02248    and is limited to its needs.  duplicate_decls is not called;
02249    if there is any preexisting decl for this identifier, it is an ICE.  */
02250 
02251 tree
02252 pushdecl_top_level (tree x)
02253 {
02254   tree name;
02255   bool nested = false;
02256   gcc_assert (TREE_CODE (x) == VAR_DECL || TREE_CODE (x) == CONST_DECL);
02257 
02258   name = DECL_NAME (x);
02259 
02260  gcc_assert (TREE_CODE (x) == CONST_DECL || !I_SYMBOL_BINDING (name));
02261 
02262   if (TREE_PUBLIC (x))
02263     {
02264       bind (name, x, external_scope, /*invisible=*/true, /*nested=*/false);
02265       nested = true;
02266     }
02267   if (file_scope)
02268     bind (name, x, file_scope, /*invisible=*/false, nested);
02269 
02270   return x;
02271 }
02272 
02273 static void
02274 implicit_decl_warning (tree id, tree olddecl)
02275 {
02276   void (*diag) (const char *, ...);
02277   switch (mesg_implicit_function_declaration)
02278     {
02279     case 0: return;
02280     case 1: diag = warning; break;
02281     case 2: diag = error;   break;
02282     default: gcc_unreachable ();
02283     }
02284 
02285   diag (G_("implicit declaration of function %qE"), id);
02286   if (olddecl)
02287     locate_old_decl (olddecl, diag);
02288 }
02289 
02290 /* Generate an implicit declaration for identifier FUNCTIONID as a
02291    function of type int ().  */
02292 
02293 tree
02294 implicitly_declare (tree functionid)
02295 {
02296   struct c_binding *b;
02297   tree decl = 0;
02298   tree asmspec_tree;
02299 
02300   for (b = I_SYMBOL_BINDING (functionid); b; b = b->shadowed)
02301     {
02302       if (B_IN_SCOPE (b, external_scope))
02303   {
02304     decl = b->decl;
02305     break;
02306   }
02307     }
02308 
02309   if (decl)
02310     {
02311       if (decl == error_mark_node)
02312   return decl;
02313 
02314       /* FIXME: Objective-C has weird not-really-builtin functions
02315    which are supposed to be visible automatically.  They wind up
02316    in the external scope because they're pushed before the file
02317    scope gets created.  Catch this here and rebind them into the
02318    file scope.  */
02319       if (!DECL_BUILT_IN (decl) && DECL_IS_BUILTIN (decl))
02320   {
02321     bind (functionid, decl, file_scope,
02322     /*invisible=*/false, /*nested=*/true);
02323     return decl;
02324   }
02325       else
02326   {
02327     tree newtype = default_function_type;
02328     if (b->type)
02329       TREE_TYPE (decl) = b->type;
02330     /* Implicit declaration of a function already declared
02331        (somehow) in a different scope, or as a built-in.
02332        If this is the first time this has happened, warn;
02333        then recycle the old declaration but with the new type.  */
02334     if (!C_DECL_IMPLICIT (decl))
02335       {
02336         implicit_decl_warning (functionid, decl);
02337         C_DECL_IMPLICIT (decl) = 1;
02338       }
02339     if (DECL_BUILT_IN (decl))
02340       {
02341         newtype = build_type_attribute_variant (newtype,
02342                   TYPE_ATTRIBUTES
02343                   (TREE_TYPE (decl)));
02344         if (!comptypes (newtype, TREE_TYPE (decl)))
02345     {
02346       warning ("incompatible implicit declaration of built-in"
02347          " function %qD", decl);
02348       newtype = TREE_TYPE (decl);
02349     }
02350       }
02351     else
02352       {
02353         if (!comptypes (newtype, TREE_TYPE (decl)))
02354     {
02355       error ("incompatible implicit declaration of function %qD",
02356        decl);
02357       locate_old_decl (decl, error);
02358     }
02359       }
02360     b->type = TREE_TYPE (decl);
02361     TREE_TYPE (decl) = newtype;
02362     bind (functionid, decl, current_scope,
02363     /*invisible=*/false, /*nested=*/true);
02364     return decl;
02365   }
02366     }
02367 
02368   /* Not seen before.  */
02369   decl = build_decl (FUNCTION_DECL, functionid, default_function_type);
02370   DECL_EXTERNAL (decl) = 1;
02371   TREE_PUBLIC (decl) = 1;
02372   C_DECL_IMPLICIT (decl) = 1;
02373   implicit_decl_warning (functionid, 0);
02374   asmspec_tree = maybe_apply_renaming_pragma (decl, /*asmname=*/NULL);
02375   if (asmspec_tree)
02376     set_user_assembler_name (decl, TREE_STRING_POINTER (asmspec_tree));
02377 
02378   /* C89 says implicit declarations are in the innermost block.
02379      So we record the decl in the standard fashion.  */
02380   decl = pushdecl (decl);
02381 
02382   /* No need to call objc_check_decl here - it's a function type.  */
02383   rest_of_decl_compilation (decl, 0, 0);
02384 
02385   /* Write a record describing this implicit function declaration
02386      to the prototypes file (if requested).  */
02387   gen_aux_info_record (decl, 0, 1, 0);
02388 
02389   /* Possibly apply some default attributes to this implicit declaration.  */
02390   decl_attributes (&decl, NULL_TREE, 0);
02391 
02392   return decl;
02393 }
02394 
02395 /* Issue an error message for a reference to an undeclared variable
02396    ID, including a reference to a builtin outside of function-call
02397    context.  Establish a binding of the identifier to error_mark_node
02398    in an appropriate scope, which will suppress further errors for the
02399    same identifier.  */
02400 void
02401 undeclared_variable (tree id)
02402 {
02403   static bool already = false;
02404   struct c_scope *scope;
02405 
02406   if (current_function_decl == 0)
02407     {
02408       error ("%qE undeclared here (not in a function)", id);
02409       scope = current_scope;
02410     }
02411   else
02412     {
02413       error ("%qE undeclared (first use in this function)", id);
02414 
02415       if (!already)
02416   {
02417     error ("(Each undeclared identifier is reported only once");
02418     error ("for each function it appears in.)");
02419     already = true;
02420   }
02421 
02422       /* If we are parsing old-style parameter decls, current_function_decl
02423          will be nonnull but current_function_scope will be null.  */
02424       scope = current_function_scope ? current_function_scope : current_scope;
02425     }
02426   bind (id, error_mark_node, scope, /*invisible=*/false, /*nested=*/false);
02427 }
02428 
02429 /* Subroutine of lookup_label, declare_label, define_label: construct a
02430    LABEL_DECL with all the proper frills.  */
02431 
02432 static tree
02433 make_label (tree name, location_t location)
02434 {
02435   tree label = build_decl (LABEL_DECL, name, void_type_node);
02436 
02437   DECL_CONTEXT (label) = current_function_decl;
02438   DECL_MODE (label) = VOIDmode;
02439   DECL_SOURCE_LOCATION (label) = location;
02440 
02441   return label;
02442 }
02443 
02444 /* Get the LABEL_DECL corresponding to identifier NAME as a label.
02445    Create one if none exists so far for the current function.
02446    This is called when a label is used in a goto expression or
02447    has its address taken.  */
02448 
02449 tree
02450 lookup_label (tree name)
02451 {
02452   tree label;
02453 
02454   if (current_function_decl == 0)
02455     {
02456       error ("label %qs referenced outside of any function",
02457        IDENTIFIER_POINTER (name));
02458       return 0;
02459     }
02460 
02461   /* Use a label already defined or ref'd with this name, but not if
02462      it is inherited from a containing function and wasn't declared
02463      using __label__.  */
02464   label = I_LABEL_DECL (name);
02465   if (label && (DECL_CONTEXT (label) == current_function_decl
02466     || C_DECLARED_LABEL_FLAG (label)))
02467     {
02468       /* If the label has only been declared, update its apparent
02469    location to point here, for better diagnostics if it
02470    turns out not to have been defined.  */
02471       if (!TREE_USED (label))
02472   DECL_SOURCE_LOCATION (label) = input_location;
02473       return label;
02474     }
02475 
02476   /* No label binding for that identifier; make one.  */
02477   label = make_label (name, input_location);
02478 
02479   /* Ordinary labels go in the current function scope.  */
02480   bind (name, label, current_function_scope,
02481   /*invisible=*/false, /*nested=*/false);
02482   return label;
02483 }
02484 
02485 /* Make a label named NAME in the current function, shadowing silently
02486    any that may be inherited from containing functions or containing
02487    scopes.  This is called for __label__ declarations.  */
02488 
02489 tree
02490 declare_label (tree name)
02491 {
02492   struct c_binding *b = I_LABEL_BINDING (name);
02493   tree label;
02494 
02495   /* Check to make sure that the label hasn't already been declared
02496      at this scope */
02497   if (b && B_IN_CURRENT_SCOPE (b))
02498     {
02499       error ("duplicate label declaration %qs", IDENTIFIER_POINTER (name));
02500       locate_old_decl (b->decl, error);
02501 
02502       /* Just use the previous declaration.  */
02503       return b->decl;
02504     }
02505 
02506   label = make_label (name, input_location);
02507   C_DECLARED_LABEL_FLAG (label) = 1;
02508 
02509   /* Declared labels go in the current scope.  */
02510   bind (name, label, current_scope,
02511   /*invisible=*/false, /*nested=*/false);
02512   return label;
02513 }
02514 
02515 /* Define a label, specifying the location in the source file.
02516    Return the LABEL_DECL node for the label, if the definition is valid.
02517    Otherwise return 0.  */
02518 
02519 tree
02520 define_label (location_t location, tree name)
02521 {
02522   /* Find any preexisting label with this name.  It is an error
02523      if that label has already been defined in this function, or
02524      if there is a containing function with a declared label with
02525      the same name.  */
02526   tree label = I_LABEL_DECL (name);
02527   struct c_label_list *nlist_se, *nlist_vm;
02528 
02529   if (label
02530       && ((DECL_CONTEXT (label) == current_function_decl
02531      && DECL_INITIAL (label) != 0)
02532     || (DECL_CONTEXT (label) != current_function_decl
02533         && C_DECLARED_LABEL_FLAG (label))))
02534     {
02535       error ("%Hduplicate label %qD", &location, label);
02536       locate_old_decl (label, error);
02537       return 0;
02538     }
02539   else if (label && DECL_CONTEXT (label) == current_function_decl)
02540     {
02541       /* The label has been used or declared already in this function,
02542    but not defined.  Update its location to point to this
02543    definition.  */
02544       if (C_DECL_UNDEFINABLE_STMT_EXPR (label))
02545   error ("%Jjump into statement expression", label);
02546       if (C_DECL_UNDEFINABLE_VM (label))
02547   error ("%Jjump into scope of identifier with variably modified type",
02548          label);
02549       DECL_SOURCE_LOCATION (label) = location;
02550     }
02551   else
02552     {
02553       /* No label binding for that identifier; make one.  */
02554       label = make_label (name, location);
02555 
02556       /* Ordinary labels go in the current function scope.  */
02557       bind (name, label, current_function_scope,
02558       /*invisible=*/false, /*nested=*/false);
02559     }
02560 
02561   if (warn_traditional && !in_system_header && lookup_name (name))
02562     warning ("%Htraditional C lacks a separate namespace for labels, "
02563              "identifier %qs conflicts", &location,
02564        IDENTIFIER_POINTER (name));
02565 
02566   nlist_se = XOBNEW (&parser_obstack, struct c_label_list);
02567   nlist_se->next = label_context_stack_se->labels_def;
02568   nlist_se->label = label;
02569   label_context_stack_se->labels_def = nlist_se;
02570 
02571   nlist_vm = XOBNEW (&parser_obstack, struct c_label_list);
02572   nlist_vm->next = label_context_stack_vm->labels_def;
02573   nlist_vm->label = label;
02574   label_context_stack_vm->labels_def = nlist_vm;
02575 
02576   /* Mark label as having been defined.  */
02577   DECL_INITIAL (label) = error_mark_node;
02578   return label;
02579 }
02580 
02581 /* Given NAME, an IDENTIFIER_NODE,
02582    return the structure (or union or enum) definition for that name.
02583    If THISLEVEL_ONLY is nonzero, searches only the current_scope.
02584    CODE says which kind of type the caller wants;
02585    it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
02586    If the wrong kind of type is found, an error is reported.  */
02587 
02588 static tree
02589 lookup_tag (enum tree_code code, tree name, int thislevel_only)
02590 {
02591   struct c_binding *b = I_TAG_BINDING (name);
02592   int thislevel = 0;
02593 
02594   if (!b || !b->decl)
02595     return 0;
02596 
02597   /* We only care about whether it's in this level if
02598      thislevel_only was set or it might be a type clash.  */
02599   if (thislevel_only || TREE_CODE (b->decl) != code)
02600     {
02601       /* For our purposes, a tag in the external scope is the same as
02602    a tag in the file scope.  (Primarily relevant to Objective-C
02603    and its builtin structure tags, which get pushed before the
02604    file scope is created.)  */
02605       if (B_IN_CURRENT_SCOPE (b)
02606     || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
02607   thislevel = 1;
02608     }
02609 
02610   if (thislevel_only && !thislevel)
02611     return 0;
02612 
02613   if (TREE_CODE (b->decl) != code)
02614     {
02615       /* Definition isn't the kind we were looking for.  */
02616       pending_invalid_xref = name;
02617       pending_invalid_xref_location = input_location;
02618 
02619       /* If in the same binding level as a declaration as a tag
02620    of a different type, this must not be allowed to
02621    shadow that tag, so give the error immediately.
02622    (For example, "struct foo; union foo;" is invalid.)  */
02623       if (thislevel)
02624   pending_xref_error ();
02625     }
02626   return b->decl;
02627 }
02628 
02629 /* Print an error message now
02630    for a recent invalid struct, union or enum cross reference.
02631    We don't print them immediately because they are not invalid
02632    when used in the `struct foo;' construct for shadowing.  */
02633 
02634 void
02635 pending_xref_error (void)
02636 {
02637   if (pending_invalid_xref != 0)
02638     error ("%H%qs defined as wrong kind of tag",
02639            &pending_invalid_xref_location,
02640            IDENTIFIER_POINTER (pending_invalid_xref));
02641   pending_invalid_xref = 0;
02642 }
02643 
02644 
02645 /* Look up NAME in the current scope and its superiors
02646    in the namespace of variables, functions and typedefs.
02647    Return a ..._DECL node of some kind representing its definition,
02648    or return 0 if it is undefined.  */
02649 
02650 tree
02651 lookup_name (tree name)
02652 {
02653   struct c_binding *b = I_SYMBOL_BINDING (name);
02654   if (b && !b->invisible)
02655     return b->decl;
02656   return 0;
02657 }
02658 
02659 /* Similar to `lookup_name' but look only at the indicated scope.  */
02660 
02661 static tree
02662 lookup_name_in_scope (tree name, struct c_scope *scope)
02663 {
02664   struct c_binding *b;
02665 
02666   for (b = I_SYMBOL_BINDING (name); b; b = b->shadowed)
02667     if (B_IN_SCOPE (b, scope))
02668       return b->decl;
02669   return 0;
02670 }
02671 
02672 /* Create the predefined scalar types of C,
02673    and some nodes representing standard constants (0, 1, (void *) 0).
02674    Initialize the global scope.
02675    Make definitions for built-in primitive functions.  */
02676 
02677 void
02678 c_init_decl_processing (void)
02679 {
02680   tree endlink;
02681   tree ptr_ftype_void, ptr_ftype_ptr;
02682   location_t save_loc = input_location;
02683 
02684   /* Adds some ggc roots, and reserved words for c-parse.in.  */
02685   c_parse_init ();
02686 
02687   current_function_decl = 0;
02688 
02689   gcc_obstack_init (&parser_obstack);
02690 
02691   /* Make the externals scope.  */
02692   push_scope ();
02693   external_scope = current_scope;
02694 
02695   /* Declarations from c_common_nodes_and_builtins must not be associated
02696      with this input file, lest we get differences between using and not
02697      using preprocessed headers.  */
02698 #ifdef USE_MAPPED_LOCATION
02699   input_location = BUILTINS_LOCATION;
02700 #else
02701   input_location.file = "<built-in>";
02702   input_location.line = 0;
02703 #endif
02704 
02705   build_common_tree_nodes (flag_signed_char, false);
02706 
02707   c_common_nodes_and_builtins ();
02708 
02709   /* In C, comparisons and TRUTH_* expressions have type int.  */
02710   truthvalue_type_node = integer_type_node;
02711   truthvalue_true_node = integer_one_node;
02712   truthvalue_false_node = integer_zero_node;
02713 
02714   /* Even in C99, which has a real boolean type.  */
02715   pushdecl (build_decl (TYPE_DECL, get_identifier ("_Bool"),
02716       boolean_type_node));
02717 
02718   endlink = void_list_node;
02719   ptr_ftype_void = build_function_type (ptr_type_node, endlink);
02720   ptr_ftype_ptr
02721     = build_function_type (ptr_type_node,
02722          tree_cons (NULL_TREE, ptr_type_node, endlink));
02723 
02724   input_location = save_loc;
02725 
02726   pedantic_lvalues = true;
02727 
02728   make_fname_decl = c_make_fname_decl;
02729   start_fname_decls ();
02730 }
02731 
02732 /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give the
02733    decl, NAME is the initialization string and TYPE_DEP indicates whether
02734    NAME depended on the type of the function.  As we don't yet implement
02735    delayed emission of static data, we mark the decl as emitted
02736    so it is not placed in the output.  Anything using it must therefore pull
02737    out the STRING_CST initializer directly.  FIXME.  */
02738 
02739 static tree
02740 c_make_fname_decl (tree id, int type_dep)
02741 {
02742   const char *name = fname_as_string (type_dep);
02743   tree decl, type, init;
02744   size_t length = strlen (name);
02745 
02746   type = build_array_type (char_type_node,
02747          build_index_type (size_int (length)));
02748   type = c_build_qualified_type (type, TYPE_QUAL_CONST);
02749 
02750   decl = build_decl (VAR_DECL, id, type);
02751 
02752   TREE_STATIC (decl) = 1;
02753   TREE_READONLY (decl) = 1;
02754   DECL_ARTIFICIAL (decl) = 1;
02755 
02756   init = build_string (length + 1, name);
02757   free ((char *) name);
02758   TREE_TYPE (init) = type;
02759   DECL_INITIAL (decl) = init;
02760 
02761   TREE_USED (decl) = 1;
02762 
02763   if (current_function_decl)
02764     {
02765       DECL_CONTEXT (decl) = current_function_decl;
02766       bind (id, decl, current_function_scope,
02767       /*invisible=*/false, /*nested=*/false);
02768     }
02769 
02770   finish_decl (decl, init, NULL_TREE);
02771 
02772   return decl;
02773 }
02774 
02775 /* Return a definition for a builtin function named NAME and whose data type
02776    is TYPE.  TYPE should be a function type with argument types.
02777    FUNCTION_CODE tells later passes how to compile calls to this function.
02778    See tree.h for its possible values.
02779 
02780    If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
02781    the name to be called if we can't opencode the function.  If
02782    ATTRS is nonzero, use that for the function's attribute list.  */
02783 
02784 tree
02785 builtin_function (const char *name, tree type, int function_code,
02786       enum built_in_class cl, const char *library_name,
02787       tree attrs)
02788 {
02789   tree id = get_identifier (name);
02790   tree decl = build_decl (FUNCTION_DECL, id, type);
02791   TREE_PUBLIC (decl) = 1;
02792   DECL_EXTERNAL (decl) = 1;
02793   DECL_LANG_SPECIFIC (decl) = GGC_CNEW (struct lang_decl);
02794   DECL_BUILT_IN_CLASS (decl) = cl;
02795   DECL_FUNCTION_CODE (decl) = function_code;
02796   C_DECL_BUILTIN_PROTOTYPE (decl) = (TYPE_ARG_TYPES (type) != 0);
02797   if (library_name)
02798     SET_DECL_ASSEMBLER_NAME (decl, get_identifier (library_name));
02799 
02800   /* Should never be called on a symbol with a preexisting meaning.  */
02801   gcc_assert (!I_SYMBOL_BINDING (id));
02802 
02803   bind (id, decl, external_scope, /*invisible=*/true, /*nested=*/false);
02804 
02805   /* Builtins in the implementation namespace are made visible without
02806      needing to be explicitly declared.  See push_file_scope.  */
02807   if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1])))
02808     {
02809       TREE_CHAIN (decl) = visible_builtins;
02810       visible_builtins = decl;
02811     }
02812 
02813   /* Possibly apply some default attributes to this built-in function.  */
02814   if (attrs)
02815     decl_attributes (&decl, attrs, ATTR_FLAG_BUILT_IN);
02816   else
02817     decl_attributes (&decl, NULL_TREE, 0);
02818 
02819   return decl;
02820 }
02821 
02822 /* Called when a declaration is seen that contains no names to declare.
02823    If its type is a reference to a structure, union or enum inherited
02824    from a containing scope, shadow that tag name for the current scope
02825    with a forward reference.
02826    If its type defines a new named structure or union
02827    or defines an enum, it is valid but we need not do anything here.
02828    Otherwise, it is an error.  */
02829 
02830 void
02831 shadow_tag (const struct c_declspecs *declspecs)
02832 {
02833   shadow_tag_warned (declspecs, 0);
02834 }
02835 
02836 /* WARNED is 1 if we have done a pedwarn, 2 if we have done a warning,
02837    but no pedwarn.  */
02838 void
02839 shadow_tag_warned (const struct c_declspecs *declspecs, int warned)
02840 {
02841   bool found_tag = false;
02842 
02843   if (declspecs->type && !declspecs->default_int_p && !declspecs->typedef_p)
02844     {
02845       tree value = declspecs->type;
02846       enum tree_code code = TREE_CODE (value);
02847 
02848       if (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE)
02849   /* Used to test also that TYPE_SIZE (value) != 0.
02850      That caused warning for `struct foo;' at top level in the file.  */
02851   {
02852     tree name = TYPE_NAME (value);
02853     tree t;
02854 
02855     found_tag = true;
02856 
02857     if (name == 0)
02858       {
02859         if (warned != 1 && code != ENUMERAL_TYPE)
02860     /* Empty unnamed enum OK */
02861     {
02862       pedwarn ("unnamed struct/union that defines no instances");
02863       warned = 1;
02864     }
02865       }
02866     else if (!declspecs->tag_defined_p
02867        && declspecs->storage_class != csc_none)
02868       {
02869         if (warned != 1)
02870     pedwarn ("empty declaration with storage class specifier "
02871        "does not redeclare tag");
02872         warned = 1;
02873         pending_xref_error ();
02874       }
02875     else if (!declspecs->tag_defined_p
02876        && (declspecs->const_p
02877            || declspecs->volatile_p
02878            || declspecs->restrict_p))
02879       {
02880         if (warned != 1)
02881     pedwarn ("empty declaration with type qualifier "
02882        "does not redeclare tag");
02883         warned = 1;
02884         pending_xref_error ();
02885       }
02886     else
02887       {
02888         pending_invalid_xref = 0;
02889         t = lookup_tag (code, name, 1);
02890 
02891         if (t == 0)
02892     {
02893       t = make_node (code);
02894       pushtag (name, t);
02895     }
02896       }
02897   }
02898       else
02899   {
02900     if (warned != 1 && !in_system_header)
02901       {
02902         pedwarn ("useless type name in empty declaration");
02903         warned = 1;
02904       }
02905   }
02906     }
02907   else if (warned != 1 && !in_system_header && declspecs->typedef_p)
02908     {
02909       pedwarn ("useless type name in empty declaration");
02910       warned = 1;
02911     }
02912 
02913   pending_invalid_xref = 0;
02914 
02915   if (declspecs->inline_p)
02916     {
02917       error ("%<inline%> in empty declaration");
02918       warned = 1;
02919     }
02920 
02921   if (current_scope == file_scope && declspecs->storage_class == csc_auto)
02922     {
02923       error ("%<auto%> in file-scope empty declaration");
02924       warned = 1;
02925     }
02926 
02927   if (current_scope == file_scope && declspecs->storage_class == csc_register)
02928     {
02929       error ("%<register%> in file-scope empty declaration");
02930       warned = 1;
02931     }
02932 
02933   if (!warned && !in_system_header && declspecs->storage_class != csc_none)
02934     {
02935       warning ("useless storage class specifier in empty declaration");
02936       warned = 2;
02937     }
02938 
02939   if (!warned && !in_system_header && declspecs->thread_p)
02940     {
02941       warning ("useless %<__thread%> in empty declaration");
02942       warned = 2;
02943     }
02944 
02945   if (!warned && !in_system_header && (declspecs->const_p
02946                || declspecs->volatile_p
02947                || declspecs->restrict_p))
02948     {
02949       warning ("useless type qualifier in empty declaration");
02950       warned = 2;
02951     }
02952 
02953   if (warned != 1)
02954     {
02955       if (!found_tag)
02956   pedwarn ("empty declaration");
02957     }
02958 }
02959 
02960 
02961 /* Return the qualifiers from SPECS as a bitwise OR of TYPE_QUAL_*
02962    bits.  SPECS represents declaration specifiers that the grammar
02963    only permits to contain type qualifiers and attributes.  */
02964 
02965 int
02966 quals_from_declspecs (const struct c_declspecs *specs)
02967 {
02968   int quals = ((specs->const_p ? TYPE_QUAL_CONST : 0)
02969          | (specs->volatile_p ? TYPE_QUAL_VOLATILE : 0)
02970          | (specs->restrict_p ? TYPE_QUAL_RESTRICT : 0));
02971   gcc_assert (!specs->type
02972         && !specs->decl_attr
02973         && specs->typespec_word == cts_none
02974         && specs->storage_class == csc_none
02975         && !specs->typedef_p
02976         && !specs->explicit_signed_p
02977         && !specs->deprecated_p
02978         && !specs->long_p
02979         && !specs->long_long_p
02980         && !specs->short_p
02981         && !specs->signed_p
02982         && !specs->unsigned_p
02983         && !specs->complex_p
02984         && !specs->inline_p
02985         && !specs->thread_p);
02986   return quals;
02987 }
02988 
02989 /* Construct an array declarator.  EXPR is the expression inside [], or
02990    NULL_TREE.  QUALS are the type qualifiers inside the [] (to be applied
02991    to the pointer to which a parameter array is converted).  STATIC_P is
02992    true if "static" is inside the [], false otherwise.  VLA_UNSPEC_P
02993    is true if the array is [*], a VLA of unspecified length which is
02994    nevertheless a complete type (not currently implemented by GCC),
02995    false otherwise.  The field for the contained declarator is left to be
02996    filled in by set_array_declarator_inner.  */
02997 
02998 struct c_declarator *
02999 build_array_declarator (tree expr, struct c_declspecs *quals, bool static_p,
03000       bool vla_unspec_p)
03001 {
03002   struct c_declarator *declarator = XOBNEW (&parser_obstack,
03003               struct c_declarator);
03004   declarator->kind = cdk_array;
03005   declarator->declarator = 0;
03006   declarator->u.array.dimen = expr;
03007   if (quals)
03008     {
03009       declarator->u.array.attrs = quals->attrs;
03010       declarator->u.array.quals = quals_from_declspecs (quals);
03011     }
03012   else
03013     {
03014       declarator->u.array.attrs = NULL_TREE;
03015       declarator->u.array.quals = 0;
03016     }
03017   declarator->u.array.static_p = static_p;
03018   declarator->u.array.vla_unspec_p = vla_unspec_p;
03019   if (pedantic && !flag_isoc99)
03020     {
03021       if (static_p || quals != NULL)
03022   pedwarn ("ISO C90 does not support %<static%> or type "
03023      "qualifiers in parameter array declarators");
03024       if (vla_unspec_p)
03025   pedwarn ("ISO C90 does not support %<[*]%> array declarators");
03026     }
03027   if (vla_unspec_p)
03028     warning ("GCC does not yet properly implement %<[*]%> array declarators");
03029   return declarator;
03030 }
03031 
03032 /* Set the contained declarator of an array declarator.  DECL is the
03033    declarator, as constructed by build_array_declarator; INNER is what
03034    appears on the left of the [].  ABSTRACT_P is true if it is an
03035    abstract declarator, false otherwise; this is used to reject static
03036    and type qualifiers in abstract declarators, where they are not in
03037    the C99 grammar (subject to possible change in DR#289).  */
03038 
03039 struct c_declarator *
03040 set_array_declarator_inner (struct c_declarator *decl,
03041           struct c_declarator *inner, bool abstract_p)
03042 {
03043   decl->declarator = inner;
03044   if (abstract_p && (decl->u.array.quals != TYPE_UNQUALIFIED
03045          || decl->u.array.attrs != NULL_TREE
03046          || decl->u.array.static_p))
03047     error ("static or type qualifiers in abstract declarator");
03048   return decl;
03049 }
03050 
03051 /* Decode a "typename", such as "int **", returning a ..._TYPE node.  */
03052 
03053 tree
03054 groktypename (struct c_type_name *type_name)
03055 {
03056   tree type;
03057   tree attrs = type_name->specs->attrs;
03058 
03059   type_name->specs->attrs = NULL_TREE;
03060 
03061   type = grokdeclarator (type_name->declarator, type_name->specs, TYPENAME,
03062        false, NULL);
03063 
03064   /* Apply attributes.  */
03065   decl_attributes (&type, attrs, 0);
03066 
03067   return type;
03068 }
03069 
03070 /* Decode a declarator in an ordinary declaration or data definition.
03071    This is called as soon as the type information and variable name
03072    have been parsed, before parsing the initializer if any.
03073    Here we create the ..._DECL node, fill in its type,
03074    and put it on the list of decls for the current context.
03075    The ..._DECL node is returned as the value.
03076 
03077    Exception: for arrays where the length is not specified,
03078    the type is left null, to be filled in by `finish_decl'.
03079 
03080    Function definitions do not come here; they go to start_function
03081    instead.  However, external and forward declarations of functions
03082    do go through here.  Structure field declarations are done by
03083    grokfield and not through here.  */
03084 
03085 tree
03086 start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs,
03087       bool initialized, tree attributes)
03088 {
03089   tree decl;
03090   tree tem;
03091 
03092   /* An object declared as __attribute__((deprecated)) suppresses
03093      warnings of uses of other deprecated items.  */
03094   if (lookup_attribute ("deprecated", attributes))
03095     deprecated_state = DEPRECATED_SUPPRESS;
03096 
03097   decl = grokdeclarator (declarator, declspecs,
03098        NORMAL, initialized, NULL);
03099   if (!decl)
03100     return 0;
03101 
03102   deprecated_state = DEPRECATED_NORMAL;
03103 
03104   if (warn_main > 0 && TREE_CODE (decl) != FUNCTION_DECL
03105       && MAIN_NAME_P (DECL_NAME (decl)))
03106     warning ("%J%qD is usually a function", decl, decl);
03107 
03108   if (initialized)
03109     /* Is it valid for this decl to have an initializer at all?
03110        If not, set INITIALIZED to zero, which will indirectly
03111        tell 'finish_decl' to ignore the initializer once it is parsed.  */
03112     switch (TREE_CODE (decl))
03113       {
03114       case TYPE_DECL:
03115   error ("typedef %qD is initialized (use __typeof__ instead)", decl);
03116   initialized = 0;
03117   break;
03118 
03119       case FUNCTION_DECL:
03120   error ("function %qD is initialized like a variable", decl);
03121   initialized = 0;
03122   break;
03123 
03124       case PARM_DECL:
03125   /* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE.  */
03126   error ("parameter %qD is initialized", decl);
03127   initialized = 0;
03128   break;
03129 
03130       default:
03131   /* Don't allow initializations for incomplete types except for
03132      arrays which might be completed by the initialization.  */
03133 
03134   /* This can happen if the array size is an undefined macro.
03135      We already gave a warning, so we don't need another one.  */
03136   if (TREE_TYPE (decl) == error_mark_node)
03137     initialized = 0;
03138   else if (COMPLETE_TYPE_P (TREE_TYPE (decl)))
03139     {
03140       /* A complete type is ok if size is fixed.  */
03141 
03142       if (TREE_CODE (TYPE_SIZE (TREE_TYPE (decl))) != INTEGER_CST
03143     || C_DECL_VARIABLE_SIZE (decl))
03144         {
03145     error ("variable-sized object may not be initialized");
03146     initialized = 0;
03147         }
03148     }
03149   else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE)
03150     {
03151       error ("variable %qD has initializer but incomplete type", decl);
03152       initialized = 0;
03153     }
03154   else if (C_DECL_VARIABLE_SIZE (decl))
03155     {
03156       /* Although C99 is unclear about whether incomplete arrays
03157          of VLAs themselves count as VLAs, it does not make
03158          sense to permit them to be initialized given that
03159          ordinary VLAs may not be initialized.  */
03160       error ("variable-sized object may not be initialized");
03161       initialized = 0;
03162     }
03163       }
03164 
03165   if (initialized)
03166     {
03167       if (current_scope == file_scope)
03168   TREE_STATIC (decl) = 1;
03169 
03170       /* Tell 'pushdecl' this is an initialized decl
03171    even though we don't yet have the initializer expression.
03172    Also tell 'finish_decl' it may store the real initializer.  */
03173       DECL_INITIAL (decl) = error_mark_node;
03174     }
03175 
03176   /* If this is a function declaration, write a record describing it to the
03177      prototypes file (if requested).  */
03178 
03179   if (TREE_CODE (decl) == FUNCTION_DECL)
03180     gen_aux_info_record (decl, 0, 0, TYPE_ARG_TYPES (TREE_TYPE (decl)) != 0);
03181 
03182   /* ANSI specifies that a tentative definition which is not merged with
03183      a non-tentative definition behaves exactly like a definition with an
03184      initializer equal to zero.  (Section 3.7.2)
03185 
03186      -fno-common gives strict ANSI behavior, though this tends to break
03187      a large body of code that grew up without this rule.
03188 
03189      Thread-local variables are never common, since there's no entrenched
03190      body of code to break, and it allows more efficient variable references
03191      in the presence of dynamic linking.  */
03192 
03193   if (TREE_CODE (decl) == VAR_DECL
03194       && !initialized
03195       && TREE_PUBLIC (decl)
03196       && !DECL_THREAD_LOCAL (decl)
03197       && !flag_no_common)
03198     DECL_COMMON (decl) = 1;
03199 
03200   /* Set attributes here so if duplicate decl, will have proper attributes.  */
03201   decl_attributes (&decl, attributes, 0);
03202 
03203   if (TREE_CODE (decl) == FUNCTION_DECL
03204       && targetm.calls.promote_prototypes (TREE_TYPE (decl)))
03205     {
03206       struct c_declarator *ce = declarator;
03207 
03208       if (ce->kind == cdk_pointer)
03209   ce = declarator->declarator;
03210       if (ce->kind == cdk_function)
03211   {
03212     tree args = ce->u.arg_info->parms;
03213     for (; args; args = TREE_CHAIN (args))
03214       {
03215         tree type = TREE_TYPE (args);
03216         if (type && INTEGRAL_TYPE_P (type)
03217       && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
03218     DECL_ARG_TYPE (args) = integer_type_node;
03219       }
03220   }
03221     }
03222 
03223   if (TREE_CODE (decl) == FUNCTION_DECL
03224       && DECL_DECLARED_INLINE_P (decl)
03225       && DECL_UNINLINABLE (decl)
03226       && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
03227     warning ("%Jinline function %qD given attribute noinline", decl, decl);
03228 
03229   /* Add this decl to the current scope.
03230      TEM may equal DECL or it may be a previous decl of the same name.  */
03231   tem = pushdecl (decl);
03232 
03233   if (initialized && DECL_EXTERNAL (tem))
03234     {
03235       DECL_EXTERNAL (tem) = 0;
03236       TREE_STATIC (tem) = 1;
03237     }
03238 
03239   return tem;
03240 }
03241 
03242 /* Finish processing of a declaration;
03243    install its initial value.
03244    If the length of an array type is not known before,
03245    it must be determined now, from the initial value, or it is an error.  */
03246 
03247 void
03248 finish_decl (tree decl, tree init, tree asmspec_tree)
03249 {
03250   tree type = TREE_TYPE (decl);
03251   int was_incomplete = (DECL_SIZE (decl) == 0);
03252   const char *asmspec = 0;
03253 
03254   /* If a name was specified, get the string.  */
03255   if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
03256       && DECL_FILE_SCOPE_P (decl))
03257     asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
03258   if (asmspec_tree)
03259     asmspec = TREE_STRING_POINTER (asmspec_tree);
03260 
03261   /* If `start_decl' didn't like having an initialization, ignore it now.  */
03262   if (init != 0 && DECL_INITIAL (decl) == 0)
03263     init = 0;
03264 
03265   /* Don't crash if parm is initialized.  */
03266   if (TREE_CODE (decl) == PARM_DECL)
03267     init = 0;
03268 
03269   if (init)
03270     store_init_value (decl, init);
03271 
03272   if (c_dialect_objc () && (TREE_CODE (decl) == VAR_DECL
03273           || TREE_CODE (decl) == FUNCTION_DECL
03274           || TREE_CODE (decl) == FIELD_DECL))
03275     objc_check_decl (decl);
03276 
03277   /* Deduce size of array from initialization, if not already known.  */
03278   if (TREE_CODE (type) == ARRAY_TYPE
03279       && TYPE_DOMAIN (type) == 0
03280       && TREE_CODE (decl) != TYPE_DECL)
03281     {
03282       bool do_default
03283   = (TREE_STATIC (decl)
03284      /* Even if pedantic, an external linkage array
03285         may have incomplete type at first.  */
03286      ? pedantic && !TREE_PUBLIC (decl)
03287      : !DECL_EXTERNAL (decl));
03288       int failure
03289   = complete_array_type (&TREE_TYPE (decl), DECL_INITIAL (decl),
03290              do_default);
03291 
03292       /* Get the completed type made by complete_array_type.  */
03293       type = TREE_TYPE (decl);
03294 
03295       switch (failure)
03296   {
03297   case 1:
03298     error ("%Jinitializer fails to determine size of %qD", decl, decl);
03299     break;
03300 
03301   case 2:
03302     if (do_default)
03303       error ("%Jarray size missing in %qD", decl, decl);
03304     /* If a `static' var's size isn't known,
03305        make it extern as well as static, so it does not get
03306        allocated.
03307        If it is not `static', then do not mark extern;
03308        finish_incomplete_decl will give it a default size
03309        and it will get allocated.  */
03310     else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
03311       DECL_EXTERNAL (decl) = 1;
03312     break;
03313 
03314   case 3:
03315     error ("%Jzero or negative size array %qD", decl, decl);
03316     break;
03317 
03318   case 0:
03319     /* For global variables, update the copy of the type that
03320        exists in the binding.  */
03321     if (TREE_PUBLIC (decl))
03322       {
03323         struct c_binding *b_ext = I_SYMBOL_BINDING (DECL_NAME (decl));
03324         while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext))
03325     b_ext = b_ext->shadowed;
03326         if (b_ext)
03327     {
03328       if (b_ext->type)
03329         b_ext->type = composite_type (b_ext->type, type);
03330       else
03331         b_ext->type = type;
03332     }
03333       }
03334     break;
03335 
03336   default:
03337     gcc_unreachable ();
03338   }
03339 
03340       if (DECL_INITIAL (decl))
03341   TREE_TYPE (DECL_INITIAL (decl)) = type;
03342 
03343       layout_decl (decl, 0);
03344     }
03345 
03346   if (TREE_CODE (decl) == VAR_DECL)
03347     {
03348       if (DECL_SIZE (decl) == 0 && TREE_TYPE (decl) != error_mark_node
03349     && COMPLETE_TYPE_P (TREE_TYPE (decl)))
03350   layout_decl (decl, 0);
03351 
03352       if (DECL_SIZE (decl) == 0
03353     /* Don't give an error if we already gave one earlier.  */
03354     && TREE_TYPE (decl) != error_mark_node
03355     && (TREE_STATIC (decl)
03356         /* A static variable with an incomplete type
03357      is an error if it is initialized.
03358      Also if it is not file scope.
03359      Otherwise, let it through, but if it is not `extern'
03360      then it may cause an error message later.  */
03361         ? (DECL_INITIAL (decl) != 0
03362      || !DECL_FILE_SCOPE_P (decl))
03363         /* An automatic variable with an incomplete type
03364      is an error.  */
03365         : !DECL_EXTERNAL (decl)))
03366    {
03367      error ("%Jstorage size of %qD isn%'t known", decl, decl);
03368      TREE_TYPE (decl) = error_mark_node;
03369    }
03370 
03371       if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
03372     && DECL_SIZE (decl) != 0)
03373   {
03374     if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
03375       constant_expression_warning (DECL_SIZE (decl));
03376     else
03377       error ("%Jstorage size of %qD isn%'t constant", decl, decl);
03378   }
03379 
03380       if (TREE_USED (type))
03381   TREE_USED (decl) = 1;
03382     }
03383 
03384   /* If this is a function and an assembler name is specified, reset DECL_RTL
03385      so we can give it its new name.  Also, update built_in_decls if it
03386      was a normal built-in.  */
03387   if (TREE_CODE (decl) == FUNCTION_DECL && asmspec)
03388     {
03389       if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL)
03390   set_builtin_user_assembler_name (decl, asmspec);
03391       set_user_assembler_name (decl, asmspec);
03392     }
03393 
03394   /* If #pragma weak was used, mark the decl weak now.  */
03395   maybe_apply_pragma_weak (decl);
03396 
03397   /* If this is a variable definition, determine its ELF visibility.  */
03398   if (TREE_CODE (decl) == VAR_DECL 
03399       && TREE_STATIC (decl) 
03400       && !DECL_EXTERNAL (decl))
03401     c_determine_visibility (decl);
03402 
03403   /* Output the assembler code and/or RTL code for variables and functions,
03404      unless the type is an undefined structure or union.
03405      If not, it will get done when the type is completed.  */
03406 
03407   if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
03408     {
03409       /* This is a no-op in c-lang.c or something real in objc-act.c.  */
03410       if (c_dialect_objc ())
03411   objc_check_decl (decl);
03412 
03413       if (asmspec) 
03414   {
03415     /* If this is not a static variable, issue a warning.
03416        It doesn't make any sense to give an ASMSPEC for an
03417        ordinary, non-register local variable.  Historically,
03418        GCC has accepted -- but ignored -- the ASMSPEC in
03419        this case.  */
03420     if (!DECL_FILE_SCOPE_P (decl)
03421         && TREE_CODE (decl) == VAR_DECL
03422         && !C_DECL_REGISTER (decl)
03423         && !TREE_STATIC (decl))
03424       warning ("%Jignoring asm-specifier for non-static local "
03425          "variable %qD", decl, decl);
03426     else if (C_DECL_REGISTER (decl))
03427       change_decl_assembler_name (decl, get_identifier (asmspec));
03428     else
03429       set_user_assembler_name (decl, asmspec);
03430   }
03431       
03432       if (DECL_FILE_SCOPE_P (decl))
03433   {
03434     if (DECL_INITIAL (decl) == NULL_TREE
03435         || DECL_INITIAL (decl) == error_mark_node)
03436       /* Don't output anything
03437          when a tentative file-scope definition is seen.
03438          But at end of compilation, do output code for them.  */
03439       DECL_DEFER_OUTPUT (decl) = 1;
03440     rest_of_decl_compilation (decl, true, 0);
03441   }
03442       else
03443   {
03444     /* In conjunction with an ASMSPEC, the `register'
03445        keyword indicates that we should place the variable
03446        in a particular register.  */
03447     if (asmspec && C_DECL_REGISTER (decl))
03448       {
03449         DECL_HARD_REGISTER (decl) = 1;
03450         /* This cannot be done for a structure with volatile
03451      fields, on which DECL_REGISTER will have been
03452      reset.  */
03453         if (!DECL_REGISTER (decl))
03454     error ("cannot put object with volatile field into register");
03455       }
03456 
03457     if (TREE_CODE (decl) != FUNCTION_DECL)
03458       {
03459         /* If we're building a variable sized type, and we might be
03460      reachable other than via the top of the current binding
03461      level, then create a new BIND_EXPR so that we deallocate
03462      the object at the right time.  */
03463         /* Note that DECL_SIZE can be null due to errors.  */
03464         if (DECL_SIZE (decl)
03465       && !TREE_CONSTANT (DECL_SIZE (decl))
03466       && STATEMENT_LIST_HAS_LABEL (cur_stmt_list))
03467     {
03468       tree bind;
03469       bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
03470       TREE_SIDE_EFFECTS (bind) = 1;
03471       add_stmt (bind);
03472       BIND_EXPR_BODY (bind) = push_stmt_list ();
03473     }
03474         add_stmt (build_stmt (DECL_EXPR, decl));
03475       }
03476   }
03477   
03478 
03479       if (!DECL_FILE_SCOPE_P (decl))
03480   {
03481     /* Recompute the RTL of a local array now
03482        if it used to be an incomplete type.  */
03483     if (was_incomplete
03484         && !TREE_STATIC (decl) && !DECL_EXTERNAL (decl))
03485       {
03486         /* If we used it already as memory, it must stay in memory.  */
03487         TREE_ADDRESSABLE (decl) = TREE_USED (decl);
03488         /* If it's still incomplete now, no init will save it.  */
03489         if (DECL_SIZE (decl) == 0)
03490     DECL_INITIAL (decl) = 0;
03491       }
03492   }
03493     }
03494 
03495   /* If this was marked 'used', be sure it will be output.  */
03496   if (lookup_attribute ("used", DECL_ATTRIBUTES (decl)))
03497     mark_decl_referenced (decl);
03498 
03499   if (TREE_CODE (decl) == TYPE_DECL)
03500     {
03501       if (!DECL_FILE_SCOPE_P (decl)
03502     && variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
03503   add_stmt (build_stmt (DECL_EXPR, decl));
03504 
03505       rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl), 0);
03506     }
03507 
03508   /* At the end of a declaration, throw away any variable type sizes
03509      of types defined inside that declaration.  There is no use
03510      computing them in the following function definition.  */
03511   if (current_scope == file_scope)
03512     get_pending_sizes ();
03513 
03514   /* Install a cleanup (aka destructor) if one was given.  */
03515   if (TREE_CODE (decl) == VAR_DECL && !TREE_STATIC (decl))
03516     {
03517       tree attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl));
03518       if (attr)
03519   {
03520     tree cleanup_id = TREE_VALUE (TREE_VALUE (attr));
03521     tree cleanup_decl = lookup_name (cleanup_id);
03522     tree cleanup;
03523 
03524     /* Build "cleanup(&decl)" for the destructor.  */
03525     cleanup = build_unary_op (ADDR_EXPR, decl, 0);
03526     cleanup = build_tree_list (NULL_TREE, cleanup);
03527     cleanup = build_function_call (cleanup_decl, cleanup);
03528 
03529     /* Don't warn about decl unused; the cleanup uses it.  */
03530     TREE_USED (decl) = 1;
03531     TREE_USED (cleanup_decl) = 1;
03532 
03533     /* Initialize EH, if we've been told to do so.  */
03534     if (flag_exceptions && !c_eh_initialized_p)
03535       {
03536         c_eh_initialized_p = true;
03537         eh_personality_libfunc
03538     = init_one_libfunc (USING_SJLJ_EXCEPTIONS
03539             ? "__gcc_personality_sj0"
03540             : "__gcc_personality_v0");
03541         using_eh_for_cleanups ();
03542       }
03543 
03544     push_cleanup (decl, cleanup, false);
03545   }
03546     }
03547 }
03548 
03549 /* Given a parsed parameter declaration, decode it into a PARM_DECL.  */
03550 
03551 tree
03552 grokparm (const struct c_parm *parm)
03553 {
03554   tree decl = grokdeclarator (parm->declarator, parm->specs, PARM, false,
03555             NULL);
03556 
03557   decl_attributes (&decl, parm->attrs, 0);
03558 
03559   return decl;
03560 }
03561 
03562 /* Given a parsed parameter declaration, decode it into a PARM_DECL
03563    and push that on the current scope.  */
03564 
03565 void
03566 push_parm_decl (const struct c_parm *parm)
03567 {
03568   tree decl;
03569 
03570   decl = grokdeclarator (parm->declarator, parm->specs, PARM, false, NULL);
03571   decl_attributes (&decl, parm->attrs, 0);
03572 
03573   decl = pushdecl (decl);
03574 
03575   finish_decl (decl, NULL_TREE, NULL_TREE);
03576 }
03577 
03578 /* Mark all the parameter declarations to date as forward decls.
03579    Also diagnose use of this extension.  */
03580 
03581 void
03582 mark_forward_parm_decls (void)
03583 {
03584   struct c_binding *b;
03585 
03586   if (pedantic && !current_scope->warned_forward_parm_decls)
03587     {
03588       pedwarn ("ISO C forbids forward parameter declarations");
03589       current_scope->warned_forward_parm_decls = true;
03590     }
03591 
03592   for (b = current_scope->bindings; b; b = b->prev)
03593     if (TREE_CODE (b->decl) == PARM_DECL)
03594       TREE_ASM_WRITTEN (b->decl) = 1;
03595 }
03596 
03597 static GTY(()) int compound_literal_number;
03598 
03599 /* Build a COMPOUND_LITERAL_EXPR.  TYPE is the type given in the compound
03600    literal, which may be an incomplete array type completed by the
03601    initializer; INIT is a CONSTRUCTOR that initializes the compound
03602    literal.  */
03603 
03604 tree
03605 build_compound_literal (tree type, tree init)
03606 {
03607   /* We do not use start_decl here because we have a type, not a declarator;
03608      and do not use finish_decl because the decl should be stored inside
03609      the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_EXPR.  */
03610   tree decl;
03611   tree complit;
03612   tree stmt;
03613 
03614   if (type == error_mark_node)
03615     return error_mark_node;
03616 
03617   decl = build_decl (VAR_DECL, NULL_TREE, type);
03618   DECL_EXTERNAL (decl) = 0;
03619   TREE_PUBLIC (decl) = 0;
03620   TREE_STATIC (decl) = (current_scope == file_scope);
03621   DECL_CONTEXT (decl) = current_function_decl;
03622   TREE_USED (decl) = 1;
03623   TREE_TYPE (decl) = type;
03624   TREE_READONLY (decl) = TYPE_READONLY (type);
03625   store_init_value (decl, init);
03626 
03627   if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type))
03628     {
03629       int failure = complete_array_type (&TREE_TYPE (decl),
03630            DECL_INITIAL (decl), true);
03631       gcc_assert (!failure);
03632 
03633       type = TREE_TYPE (decl);
03634       TREE_TYPE (DECL_INITIAL (decl)) = type;
03635     }
03636 
03637   if (type == error_mark_node || !COMPLETE_TYPE_P (type))
03638     return error_mark_node;
03639 
03640   stmt = build_stmt (DECL_EXPR, decl);
03641   complit = build1 (COMPOUND_LITERAL_EXPR, type, stmt);
03642   TREE_SIDE_EFFECTS (complit) = 1;
03643 
03644   layout_decl (decl, 0);
03645 
03646   if (TREE_STATIC (decl))
03647     {
03648       /* This decl needs a name for the assembler output.  We also need
03649    a unique suffix to be added to the name.  */
03650       char *name;
03651 
03652       ASM_FORMAT_PRIVATE_NAME (name, "__compound_literal",
03653              compound_literal_number);
03654       compound_literal_number++;
03655       DECL_NAME (decl) = get_identifier (name);
03656       DECL_DEFER_OUTPUT (decl) = 1;
03657       DECL_COMDAT (decl) = 1;
03658       DECL_ARTIFICIAL (decl) = 1;
03659       DECL_IGNORED_P (decl) = 1;
03660       pushdecl (decl);
03661       rest_of_decl_compilation (decl, 1, 0);
03662     }
03663 
03664   return complit;
03665 }
03666 
03667 /* Determine whether TYPE is a structure with a flexible array member,
03668    or a union containing such a structure (possibly recursively).  */
03669 
03670 static bool
03671 flexible_array_type_p (tree type)
03672 {
03673   tree x;
03674   switch (TREE_CODE (type))
03675     {
03676     case RECORD_TYPE:
03677       x = TYPE_FIELDS (type);
03678       if (x == NULL_TREE)
03679   return false;
03680       while (TREE_CHAIN (x) != NULL_TREE)
03681   x = TREE_CHAIN (x);
03682       if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
03683     && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
03684     && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE
03685     && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE)
03686   return true;
03687       return false;
03688     case UNION_TYPE:
03689       for (x = TYPE_FIELDS (type); x != NULL_TREE; x = TREE_CHAIN (x))
03690   {
03691     if (flexible_array_type_p (TREE_TYPE (x)))
03692       return true;
03693   }
03694       return false;
03695     default:
03696     return false;
03697   }
03698 }
03699 
03700 /* Performs sanity checks on the TYPE and WIDTH of the bit-field NAME,
03701    replacing with appropriate values if they are invalid.  */
03702 static void
03703 check_bitfield_type_and_width (tree *type, tree *width, const char *orig_name)
03704 {
03705   tree type_mv;
03706   unsigned int max_width;
03707   unsigned HOST_WIDE_INT w;
03708   const char *name = orig_name ? orig_name: _("<anonymous>");
03709 
03710   /* Necessary?  */
03711   STRIP_NOPS (*width);
03712 
03713   /* Detect and ignore out of range field width and process valid
03714      field widths.  */
03715   if (!INTEGRAL_TYPE_P (TREE_TYPE (*width))
03716       || TREE_CODE (*width) != INTEGER_CST)
03717     {
03718       error ("bit-field %qs width not an integer constant", name);
03719       *width = integer_one_node;
03720     }
03721   else
03722     {
03723       constant_expression_warning (*width);
03724       if (tree_int_cst_sgn (*width) < 0)
03725   {
03726     error ("negative width in bit-field %qs", name);
03727     *width = integer_one_node;
03728   }
03729       else if (integer_zerop (*width) && orig_name)
03730   {
03731     error ("zero width for bit-field %qs", name);
03732     *width = integer_one_node;
03733   }
03734     }
03735 
03736   /* Detect invalid bit-field type.  */
03737   if (TREE_CODE (*type) != INTEGER_TYPE
03738       && TREE_CODE (*type) != BOOLEAN_TYPE
03739       && TREE_CODE (*type) != ENUMERAL_TYPE)
03740     {
03741       error ("bit-field %qs has invalid type", name);
03742       *type = unsigned_type_node;
03743     }
03744 
03745   type_mv = TYPE_MAIN_VARIANT (*type);
03746   if (pedantic
03747       && type_mv != integer_type_node
03748       && type_mv != unsigned_type_node
03749       && type_mv != boolean_type_node)
03750     pedwarn ("type of bit-field %qs is a GCC extension", name);
03751 
03752   if (type_mv == boolean_type_node)
03753     max_width = CHAR_TYPE_SIZE;
03754   else
03755     max_width = TYPE_PRECISION (*type);
03756 
03757   if (0 < compare_tree_int (*width, max_width))
03758     {
03759       error ("width of %qs exceeds its type", name);
03760       w = max_width;
03761       *width = build_int_cst (NULL_TREE, w);
03762     }
03763   else
03764     w = tree_low_cst (*width, 1);
03765 
03766   if (TREE_CODE (*type) == ENUMERAL_TYPE)
03767     {
03768       struct lang_type *lt = TYPE_LANG_SPECIFIC (*type);
03769       if (!lt
03770           || w < min_precision (lt->enum_min, TYPE_UNSIGNED (*type))
03771     || w < min_precision (lt->enum_max, TYPE_UNSIGNED (*type)))
03772   warning ("%qs is narrower than values of its type", name);
03773     }
03774 }
03775 
03776 /* Build a bit-field integer type for the given WIDTH and UNSIGNEDP.  */
03777 static tree
03778 c_build_bitfield_integer_type (unsigned HOST_WIDE_INT width, int unsignedp)
03779 {
03780   /* Extended integer types of the same width as a standard type have
03781      lesser rank, so those of the same width as int promote to int or
03782      unsigned int and are valid for printf formats expecting int or
03783      unsigned int.  To avoid such special cases, avoid creating
03784      extended integer types for bit-fields if a standard integer type
03785      is available.  */
03786   if (width == TYPE_PRECISION (integer_type_node))
03787     return unsignedp ? unsigned_type_node : integer_type_node;
03788   if (width == TYPE_PRECISION (signed_char_type_node))
03789     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
03790   if (width == TYPE_PRECISION (short_integer_type_node))
03791     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
03792   if (width == TYPE_PRECISION (long_integer_type_node))
03793     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
03794   if (width == TYPE_PRECISION (long_long_integer_type_node))
03795   {
03796 #ifdef TARG_SL
03797 
03798   if (Long_Long_Support == TRUE)
03799   {
03800     return (unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node);
03801   }
03802   else
03803   {
03804     warning("\"long long\" is mapped to \"long\", "
03805               "Please use \"-mlong-long\" option to enbale long long type suporting");
03806       return unsignedp ? long_unsigned_type_node : long_integer_type_node;
03807   }
03808 
03809 #else
03810 
03811     return (unsignedp ? long_long_unsigned_type_node
03812       : long_long_integer_type_node);
03813 
03814 #endif
03815 
03816   }
03817   return build_nonstandard_integer_type (width, unsignedp);
03818 }
03819 
03820 /* Given declspecs and a declarator,
03821    determine the name and type of the object declared
03822    and construct a ..._DECL node for it.
03823    (In one case we can return a ..._TYPE node instead.
03824     For invalid input we sometimes return 0.)
03825 
03826    DECLSPECS is a c_declspecs structure for the declaration specifiers.
03827 
03828    DECL_CONTEXT says which syntactic context this declaration is in:
03829      NORMAL for most contexts.  Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
03830      FUNCDEF for a function definition.  Like NORMAL but a few different
03831       error messages in each case.  Return value may be zero meaning
03832       this definition is too screwy to try to parse.
03833      PARM for a parameter declaration (either within a function prototype
03834       or before a function body).  Make a PARM_DECL, or return void_type_node.
03835      TYPENAME if for a typename (in a cast or sizeof).
03836       Don't make a DECL node; just return the ..._TYPE node.
03837      FIELD for a struct or union field; make a FIELD_DECL.
03838    INITIALIZED is true if the decl has an initializer.
03839    WIDTH is non-NULL for bit-fields, and is a pointer to an INTEGER_CST node
03840    representing the width of the bit-field.
03841 
03842    In the TYPENAME case, DECLARATOR is really an absolute declarator.
03843    It may also be so in the PARM case, for a prototype where the
03844    argument type is specified but not the name.
03845 
03846    This function is where the complicated C meanings of `static'
03847    and `extern' are interpreted.  */
03848 
03849 static tree
03850 grokdeclarator (const struct c_declarator *declarator,
03851     struct c_declspecs *declspecs,
03852     enum decl_context decl_context, bool initialized, tree *width)
03853 {
03854   tree type = declspecs->type;
03855   bool threadp = declspecs->thread_p;
03856   enum c_storage_class storage_class = declspecs->storage_class;
03857   int constp;
03858   int restrictp;
03859   int volatilep;
03860   int type_quals = TYPE_UNQUALIFIED;
03861   const char *name, *orig_name;
03862   tree typedef_type = 0;
03863   int funcdef_flag = 0;
03864   bool funcdef_syntax = false;
03865   int size_varies = 0;
03866   tree decl_attr = declspecs->decl_attr;
03867   int array_ptr_quals = TYPE_UNQUALIFIED;
03868   tree array_ptr_attrs = NULL_TREE;
03869   int array_parm_static = 0;
03870   tree returned_attrs = NULL_TREE;
03871   bool bitfield = width != NULL;
03872   tree element_type;
03873   struct c_arg_info *arg_info = 0;
03874 
03875   if (decl_context == FUNCDEF)
03876     funcdef_flag = 1, decl_context = NORMAL;
03877 
03878   /* Look inside a declarator for the name being declared
03879      and get it as a string, for an error message.  */
03880   {
03881     const struct c_declarator *decl = declarator;
03882     name = 0;
03883 
03884     while (decl)
03885       switch (decl->kind)
03886   {
03887   case cdk_function:
03888   case cdk_array:
03889   case cdk_pointer:
03890     funcdef_syntax = (decl->kind == cdk_function);
03891     decl = decl->declarator;
03892     break;
03893 
03894   case cdk_attrs:
03895     decl = decl->declarator;
03896     break;
03897 
03898   case cdk_id:
03899     if (decl->u.id)
03900       name = IDENTIFIER_POINTER (decl->u.id);
03901     decl = 0;
03902     break;
03903 
03904   default:
03905     gcc_unreachable ();
03906   }
03907     orig_name = name;
03908     if (name == 0)
03909       name = "type name";
03910   }
03911 
03912   /* A function definition's declarator must have the form of
03913      a function declarator.  */
03914 
03915   if (funcdef_flag && !funcdef_syntax)
03916     return 0;
03917 
03918   /* If this looks like a function definition, make it one,
03919      even if it occurs where parms are expected.
03920      Then store_parm_decls will reject it and not use it as a parm.  */
03921   if (decl_context == NORMAL && !funcdef_flag && current_scope->parm_flag)
03922     decl_context = PARM;
03923 
03924   if (declspecs->deprecated_p && deprecated_state != DEPRECATED_SUPPRESS)
03925     warn_deprecated_use (declspecs->type);
03926 
03927   typedef_type = type;
03928   size_varies = C_TYPE_VARIABLE_SIZE (type);
03929 
03930   /* Diagnose defaulting to "int".  */
03931 
03932   if (declspecs->default_int_p && !in_system_header)
03933     {
03934       /* Issue a warning if this is an ISO C 99 program or if
03935    -Wreturn-type and this is a function, or if -Wimplicit;
03936    prefer the former warning since it is more explicit.  */
03937       if ((warn_implicit_int || warn_return_type || flag_isoc99)
03938     && funcdef_flag)
03939   warn_about_return_type = 1;
03940       else if (warn_implicit_int || flag_isoc99)
03941   pedwarn_c99 ("type defaults to %<int%> in declaration of %qs", name);
03942     }
03943 
03944   /* Adjust the type if a bit-field is being declared,
03945      -funsigned-bitfields applied and the type is not explicitly
03946      "signed".  */
03947   if (bitfield && !flag_signed_bitfields && !declspecs->explicit_signed_p
03948       && TREE_CODE (type) == INTEGER_TYPE)
03949     type = c_common_unsigned_type (type);
03950 
03951   /* Figure out the type qualifiers for the declaration.  There are
03952      two ways a declaration can become qualified.  One is something
03953      like `const int i' where the `const' is explicit.  Another is
03954      something like `typedef const int CI; CI i' where the type of the
03955      declaration contains the `const'.  A third possibility is that
03956      there is a type qualifier on the element type of a typedefed
03957      array type, in which case we should extract that qualifier so
03958      that c_apply_type_quals_to_decls receives the full list of
03959      qualifiers to work with (C90 is not entirely clear about whether
03960      duplicate qualifiers should be diagnosed in this case, but it
03961      seems most appropriate to do so).  */
03962   element_type = strip_array_types (type);
03963   constp = declspecs->const_p + TYPE_READONLY (element_type);
03964   restrictp = declspecs->restrict_p + TYPE_RESTRICT (element_type);
03965   volatilep = declspecs->volatile_p + TYPE_VOLATILE (element_type);
03966   if (pedantic && !flag_isoc99)
03967     {
03968       if (constp > 1)
03969   pedwarn ("duplicate %<const%>");
03970       if (restrictp > 1)
03971   pedwarn ("duplicate %<restrict%>");
03972       if (volatilep > 1)
03973   pedwarn ("duplicate %<volatile%>");
03974     }
03975   if (!flag_gen_aux_info && (TYPE_QUALS (element_type)))
03976     type = TYPE_MAIN_VARIANT (type);
03977   type_quals = ((constp ? TYPE_QUAL_CONST : 0)
03978     | (restrictp ? TYPE_QUAL_RESTRICT : 0)
03979     | (volatilep ? TYPE_QUAL_VOLATILE : 0));
03980 
03981   /* Warn about storage classes that are invalid for certain
03982      kinds of declarations (parameters, typenames, etc.).  */
03983 
03984   if (funcdef_flag
03985       && (threadp
03986     || storage_class == csc_auto
03987     || storage_class == csc_register
03988     || storage_class == csc_typedef))
03989     {
03990       if (storage_class == csc_auto
03991     && (pedantic || current_scope == file_scope))
03992   pedwarn ("function definition declared %<auto%>");
03993       if (storage_class == csc_register)
03994   error ("function definition declared %<register%>");
03995       if (storage_class == csc_typedef)
03996   error ("function definition declared %<typedef%>");
03997       if (threadp)
03998   error ("function definition declared %<__thread%>");
03999       threadp = false;
04000       if (storage_class == csc_auto
04001     || storage_class == csc_register
04002     || storage_class == csc_typedef)
04003   storage_class = csc_none;
04004     }
04005   else if (decl_context != NORMAL && (storage_class != csc_none || threadp))
04006     {
04007       if (decl_context == PARM && storage_class == csc_register)
04008   ;
04009       else
04010   {
04011     switch (decl_context)
04012       {
04013       case FIELD:
04014         error ("storage class specified for structure field %qs",
04015          name);
04016         break;
04017       case PARM:
04018         error ("storage class specified for parameter %qs", name);
04019         break;
04020       default:
04021         error ("storage class specified for typename");
04022         break;
04023       }
04024     storage_class = csc_none;
04025     threadp = false;
04026   }
04027     }
04028   else if (storage_class == csc_extern
04029      && initialized
04030      && !funcdef_flag)
04031     {
04032       /* 'extern' with initialization is invalid if not at file scope.  */
04033       if (current_scope == file_scope)
04034   warning ("%qs initialized and declared %<extern%>", name);
04035       else
04036   error ("%qs has both %<extern%> and initializer", name);
04037     }
04038   else if (current_scope == file_scope)
04039     {
04040       if (storage_class == csc_auto)
04041   error ("file-scope declaration of %qs specifies %<auto%>", name);
04042       if (pedantic && storage_class == csc_register)
04043   pedwarn ("file-scope declaration of %qs specifies %<register%>", name);
04044     }
04045   else
04046     {
04047       if (storage_class == csc_extern && funcdef_flag)
04048   error ("nested function %qs declared %<extern%>", name);
04049       else if (threadp && storage_class == csc_none)
04050   {
04051     error ("function-scope %qs implicitly auto and declared "
04052      "%<__thread%>",
04053      name);
04054     threadp = false;
04055   }
04056     }
04057 
04058   /* Now figure out the structure of the declarator proper.
04059      Descend through it, creating more complex types, until we reach
04060      the declared identifier (or NULL_TREE, in an absolute declarator).
04061      At each stage we maintain an unqualified version of the type
04062      together with any qualifiers that should be applied to it with
04063      c_build_qualified_type; this way, array types including
04064      multidimensional array types are first built up in unqualified
04065      form and then the qualified form is created with
04066      TYPE_MAIN_VARIANT pointing to the unqualified form.  */
04067 
04068   while (declarator && declarator->kind != cdk_id)
04069     {
04070       if (type == error_mark_node)
04071   {
04072     declarator = declarator->declarator;
04073     continue;
04074   }
04075 
04076       /* Each level of DECLARATOR is either a cdk_array (for ...[..]),
04077    a cdk_pointer (for *...),
04078    a cdk_function (for ...(...)),
04079    a cdk_attrs (for nested attributes),
04080    or a cdk_id (for the name being declared
04081    or the place in an absolute declarator
04082    where the name was omitted).
04083    For the last case, we have just exited the loop.
04084 
04085    At this point, TYPE is the type of elements of an array,
04086    or for a function to return, or for a pointer to point to.
04087    After this sequence of ifs, TYPE is the type of the
04088    array or function or pointer, and DECLARATOR has had its
04089    outermost layer removed.  */
04090 
04091       if (array_ptr_quals != TYPE_UNQUALIFIED
04092     || array_ptr_attrs != NULL_TREE
04093     || array_parm_static)
04094   {
04095     /* Only the innermost declarator (making a parameter be of
04096        array type which is converted to pointer type)
04097        may have static or type qualifiers.  */
04098     error ("static or type qualifiers in non-parameter array declarator");
04099     array_ptr_quals = TYPE_UNQUALIFIED;
04100     array_ptr_attrs = NULL_TREE;
04101     array_parm_static = 0;
04102   }
04103 
04104       switch (declarator->kind)
04105   {
04106   case cdk_attrs:
04107     {
04108       /* A declarator with embedded attributes.  */
04109       tree attrs = declarator->u.attrs;
04110       const struct c_declarator *inner_decl;
04111       int attr_flags = 0;
04112       declarator = declarator->declarator;
04113       inner_decl = declarator;
04114       while (inner_decl->kind == cdk_attrs)
04115         inner_decl = inner_decl->declarator;
04116       if (inner_decl->kind == cdk_id)
04117         attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
04118       else if (inner_decl->kind == cdk_function)
04119         attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
04120       else if (inner_decl->kind == cdk_array)
04121         attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
04122       returned_attrs = decl_attributes (&type,
04123                 chainon (returned_attrs, attrs),
04124                 attr_flags);
04125       break;
04126     }
04127   case cdk_array:
04128     {
04129       tree itype = NULL_TREE;
04130       tree size = declarator->u.array.dimen;
04131       /* The index is a signed object `sizetype' bits wide.  */
04132       tree index_type = c_common_signed_type (sizetype);
04133 
04134       array_ptr_quals = declarator->u.array.quals;
04135       array_ptr_attrs = declarator->u.array.attrs;
04136       array_parm_static = declarator->u.array.static_p;
04137       
04138       declarator = declarator->declarator;
04139 
04140       /* Check for some types that there cannot be arrays of.  */
04141       
04142       if (VOID_TYPE_P (type))
04143         {
04144     error ("declaration of %qs as array of voids", name);
04145     type = error_mark_node;
04146         }
04147       
04148       if (TREE_CODE (type) == FUNCTION_TYPE)
04149         {
04150     error ("declaration of %qs as array of functions", name);
04151     type = error_mark_node;
04152         }
04153       
04154       if (pedantic && !in_system_header && flexible_array_type_p (type))
04155         pedwarn ("invalid use of structure with flexible array member");
04156       
04157       if (size == error_mark_node)
04158         type = error_mark_node;
04159       
04160       if (type == error_mark_node)
04161         continue;
04162 
04163       /* If size was specified, set ITYPE to a range-type for
04164          that size.  Otherwise, ITYPE remains null.  finish_decl
04165          may figure it out from an initial value.  */
04166 
04167       if (size)
04168         {
04169     /* Strip NON_LVALUE_EXPRs since we aren't using as an
04170        lvalue.  */
04171     STRIP_TYPE_NOPS (size);
04172     
04173     if (!INTEGRAL_TYPE_P (TREE_TYPE (size)))
04174       {
04175         error ("size of array %qs has non-integer type", name);
04176         size = integer_one_node;
04177       }
04178     
04179     if (pedantic && integer_zerop (size))
04180       pedwarn ("ISO C forbids zero-size array %qs", name);
04181     
04182     if (TREE_CODE (size) == INTEGER_CST)
04183       {
04184         constant_expression_warning (size);
04185         if (tree_int_cst_sgn (size) < 0)
04186           {
04187       error ("size of array %qs is negative", name);
04188       size = integer_one_node;
04189           }
04190       }
04191     else
04192       {
04193         /* Make sure the array size remains visibly
04194            nonconstant even if it is (eg) a const variable
04195            with known value.  */
04196         size_varies = 1;
04197         
04198         if (!flag_isoc99 && pedantic)
04199           {
04200       if (TREE_CONSTANT (size))
04201         pedwarn ("ISO C90 forbids array %qs whose size "
04202            "can%'t be evaluated",
04203            name);
04204       else
04205         pedwarn ("ISO C90 forbids variable-size array %qs",
04206            name);
04207           }
04208       }
04209 
04210     if (integer_zerop (size))
04211       {
04212         /*  A zero-length array cannot be represented with
04213             an unsigned index type, which is what we'll
04214             get with build_index_type.  Create an
04215             open-ended range instead.  */
04216         itype = build_range_type (sizetype, size, NULL_TREE);
04217       }
04218     else
04219       {
04220         /* Arrange for the SAVE_EXPR on the inside of the
04221            MINUS_EXPR, which allows the -1 to get folded
04222            with the +1 that happens when building TYPE_SIZE.  */
04223         if (size_varies)
04224           size = variable_size (size);
04225 
04226         /* Compute the maximum valid index, that is, size
04227            - 1.  Do the calculation in index_type, so that
04228            if it is a variable the computations will be
04229            done in the proper mode.  */
04230         itype = fold (build2 (MINUS_EXPR, index_type,
04231             convert (index_type, size),
04232             convert (index_type,
04233                size_one_node)));
04234 
04235         /* If that overflowed, the array is too big.  ??? 
04236            While a size of INT_MAX+1 technically shouldn't
04237            cause an overflow (because we subtract 1), the
04238            overflow is recorded during the conversion to
04239            index_type, before the subtraction.  Handling
04240            this case seems like an unnecessary
04241            complication.  */
04242         if (TREE_OVERFLOW (itype))
04243           {
04244       error ("size of array %qs is too large", name);
04245       type = error_mark_node;
04246       continue;
04247           }
04248         
04249         itype = build_index_type (itype);
04250       }
04251         }
04252       else if (decl_context == FIELD)
04253         {
04254     if (pedantic && !flag_isoc99 && !in_system_header)
04255       pedwarn ("ISO C90 does not support flexible array members");
04256 
04257     /* ISO C99 Flexible array members are effectively
04258        identical to GCC's zero-length array extension.  */
04259     itype = build_range_type (sizetype, size_zero_node, NULL_TREE);
04260         }
04261 
04262        /* Complain about arrays of incomplete types.  */
04263       if (!COMPLETE_TYPE_P (type))
04264         {
04265     error ("array type has incomplete element type");
04266           type = error_mark_node;
04267         }
04268       else
04269         type = build_array_type (type, itype);
04270 
04271       if (size_varies)
04272         C_TYPE_VARIABLE_SIZE (type) = 1;
04273 
04274       /* The GCC extension for zero-length arrays differs from
04275          ISO flexible array members in that sizeof yields
04276          zero.  */
04277       if (size && integer_zerop (size))
04278         {
04279     TYPE_SIZE (type) = bitsize_zero_node;
04280     TYPE_SIZE_UNIT (type) = size_zero_node;
04281         }
04282 
04283       if (decl_context != PARM
04284     && (array_ptr_quals != TYPE_UNQUALIFIED
04285         || array_ptr_attrs != NULL_TREE
04286         || array_parm_static))
04287         {
04288     error ("static or type qualifiers in non-parameter array declarator");
04289     array_ptr_quals = TYPE_UNQUALIFIED;
04290     array_ptr_attrs = NULL_TREE;
04291     array_parm_static = 0;
04292         }
04293       break;
04294     }
04295   case cdk_function:
04296     {
04297       /* Say it's a definition only for the declarator closest
04298          to the identifier, apart possibly from some
04299          attributes.  */
04300       bool really_funcdef = false;
04301       tree arg_types;
04302       if (funcdef_flag)
04303         {
04304     const struct c_declarator *t = declarator->declarator;
04305     while (t->kind == cdk_attrs)
04306       t = t->declarator;
04307     really_funcdef = (t->kind == cdk_id);
04308         }
04309 
04310       /* Declaring a function type.  Make sure we have a valid
04311          type for the function to return.  */
04312       if (type == error_mark_node)
04313         continue;
04314       
04315       size_varies = 0;
04316 
04317       /* Warn about some types functions can't return.  */
04318       if (TREE_CODE (type) == FUNCTION_TYPE)
04319         {
04320     error ("%qs declared as function returning a function", name);
04321     type = integer_type_node;
04322         }
04323       if (TREE_CODE (type) == ARRAY_TYPE)
04324         {
04325     error ("%qs declared as function returning an array", name);
04326     type = integer_type_node;
04327         }
04328 
04329       /* Construct the function type and go to the next
04330          inner layer of declarator.  */
04331       arg_info = declarator->u.arg_info;
04332       arg_types = grokparms (arg_info, really_funcdef);
04333 
04334       /* Type qualifiers before the return type of the function
04335          qualify the return type, not the function type.  */
04336       if (type_quals)
04337         {
04338           /* Type qualifiers on a function return type are
04339        normally permitted by the standard but have no
04340        effect, so give a warning at -Wreturn-type.
04341        Qualifiers on a void return type are banned on
04342        function definitions in ISO C; GCC used to used
04343        them for noreturn functions.  */
04344     if (VOID_TYPE_P (type) && really_funcdef)
04345       pedwarn ("function definition has qualified void return type");
04346     else if (warn_return_type)
04347       warning ("type qualifiers ignored on function return type");
04348     
04349     type = c_build_qualified_type (type, type_quals);
04350         }
04351       type_quals = TYPE_UNQUALIFIED;
04352       
04353       type = build_function_type (type, arg_types);
04354       declarator = declarator->declarator;
04355       
04356       /* Set the TYPE_CONTEXTs for each tagged type which is local to
04357          the formal parameter list of this FUNCTION_TYPE to point to
04358          the FUNCTION_TYPE node itself.  */
04359       {
04360         tree link;
04361         
04362         for (link = arg_info->tags;
04363        link;
04364        link = TREE_CHAIN (link))
04365     TYPE_CONTEXT (TREE_VALUE (link)) = type;
04366       }
04367       break;
04368     }
04369   case cdk_pointer:
04370     {
04371       /* Merge any constancy or volatility into the target type
04372          for the pointer.  */
04373 
04374       if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
04375     && type_quals)
04376         pedwarn ("ISO C forbids qualified function types");
04377       if (type_quals)
04378         type = c_build_qualified_type (type, type_quals);
04379       size_varies = 0;
04380 
04381       type = build_pointer_type (type);
04382       
04383       /* Process type qualifiers (such as const or volatile)
04384          that were given inside the `*'.  */
04385       type_quals = declarator->u.pointer_quals;
04386 
04387       declarator = declarator->declarator;
04388       break;
04389     }
04390   default:
04391     gcc_unreachable ();
04392   }
04393     }
04394 
04395   /* Now TYPE has the actual type, apart from any qualifiers in
04396      TYPE_QUALS.  */
04397 
04398   /* Check the type and width of a bit-field.  */
04399   if (bitfield)
04400     check_bitfield_type_and_width (&type, width, orig_name);
04401 
04402   /* Did array size calculations overflow?  */
04403 
04404   if (TREE_CODE (type) == ARRAY_TYPE
04405       && COMPLETE_TYPE_P (type)
04406       && TREE_OVERFLOW (TYPE_SIZE_UNIT (type)))
04407     {
04408       error ("size of array %qs is too large", name);
04409       /* If we proceed with the array type as it is, we'll eventually
04410    crash in tree_low_cst().  */
04411       type = error_mark_node;
04412     }
04413 
04414   /* If this is declaring a typedef name, return a TYPE_DECL.  */
04415 
04416   if (storage_class == csc_typedef)
04417     {
04418       tree decl;
04419       if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
04420     && type_quals)
04421   pedwarn ("ISO C forbids qualified function types");
04422       if (type_quals)
04423   type = c_build_qualified_type (type, type_quals);
04424       decl = build_decl (TYPE_DECL, declarator->u.id, type);
04425       if (declspecs->explicit_signed_p)
04426   C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
04427       decl_attributes (&decl, returned_attrs, 0);
04428       if (declspecs->inline_p)
04429   pedwarn ("%Jtypedef %qD declared %<inline%>", decl, decl);
04430       return decl;
04431     }
04432 
04433   /* Detect the case of an array type of unspecified size
04434      which came, as such, direct from a typedef name.
04435      We must copy the type, so that each identifier gets
04436      a distinct type, so that each identifier's size can be
04437      controlled separately by its own initializer.  */
04438 
04439   if (type != 0 && typedef_type != 0
04440       && TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == 0
04441       && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type))
04442     {
04443       type = build_array_type (TREE_TYPE (type), 0);
04444       if (size_varies)
04445   C_TYPE_VARIABLE_SIZE (type) = 1;
04446     }
04447 
04448   /* If this is a type name (such as, in a cast or sizeof),
04449      compute the type and return it now.  */
04450 
04451   if (decl_context == TYPENAME)
04452     {
04453       /* Note that the grammar rejects storage classes in typenames
04454    and fields.  */
04455       gcc_assert (storage_class == csc_none && !threadp
04456       && !declspecs->inline_p);
04457       if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
04458     && type_quals)
04459   pedwarn ("ISO C forbids const or volatile function types");
04460       if (type_quals)
04461   type = c_build_qualified_type (type, type_quals);
04462       decl_attributes (&type, returned_attrs, 0);
04463       return type;
04464     }
04465 
04466   /* Aside from typedefs and type names (handle above),
04467      `void' at top level (not within pointer)
04468      is allowed only in public variables.
04469      We don't complain about parms either, but that is because
04470      a better error message can be made later.  */
04471 
04472   if (VOID_TYPE_P (type) && decl_context != PARM
04473       && !((decl_context != FIELD && TREE_CODE (type) != FUNCTION_TYPE)
04474       && (storage_class == csc_extern
04475     || (current_scope == file_scope
04476         && !(storage_class == csc_static
04477        || storage_class == csc_register)))))
04478     {
04479       error ("variable or field %qs declared void", name);
04480       type = integer_type_node;
04481     }
04482 
04483   /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
04484      or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE.  */
04485 
04486   {
04487     tree decl;
04488 
04489     if (decl_context == PARM)
04490       {
04491   tree type_as_written;
04492   tree promoted_type;
04493 
04494   /* A parameter declared as an array of T is really a pointer to T.
04495      One declared as a function is really a pointer to a function.  */
04496 
04497   if (TREE_CODE (type) == ARRAY_TYPE)
04498     {
04499       /* Transfer const-ness of array into that of type pointed to.  */
04500       type = TREE_TYPE (type);
04501       if (type_quals)
04502         type = c_build_qualified_type (type, type_quals);
04503       type = build_pointer_type (type);
04504       type_quals = array_ptr_quals;
04505 
04506       /* We don't yet implement attributes in this context.  */
04507       if (array_ptr_attrs != NULL_TREE)
04508         warning ("attributes in parameter array declarator ignored");
04509 
04510       size_varies = 0;
04511     }
04512   else if (TREE_CODE (type) == FUNCTION_TYPE)
04513     {
04514       if (pedantic && type_quals)
04515         pedwarn ("ISO C forbids qualified function types");
04516       if (type_quals)
04517         type = c_build_qualified_type (type, type_quals);
04518       type = build_pointer_type (type);
04519       type_quals = TYPE_UNQUALIFIED;
04520     }
04521   else if (type_quals)
04522     type = c_build_qualified_type (type, type_quals);
04523 
04524   type_as_written = type;
04525 
04526   decl = build_decl (PARM_DECL, declarator->u.id, type);
04527   if (size_varies)
04528     C_DECL_VARIABLE_SIZE (decl) = 1;
04529 
04530   /* Compute the type actually passed in the parmlist,
04531      for the case where there is no prototype.
04532      (For example, shorts and chars are passed as ints.)
04533      When there is a prototype, this is overridden later.  */
04534 
04535   if (type == error_mark_node)
04536     promoted_type = type;
04537   else
04538     promoted_type = c_type_promotes_to (type);
04539 
04540   DECL_ARG_TYPE (decl) = promoted_type;
04541   DECL_ARG_TYPE_AS_WRITTEN (decl) = type_as_written;
04542   if (declspecs->inline_p)
04543     pedwarn ("%Jparameter %qD declared %<inline%>", decl, decl);
04544       }
04545     else if (decl_context == FIELD)
04546       {
04547   /* Note that the grammar rejects storage classes in typenames
04548      and fields.  */
04549   gcc_assert (storage_class == csc_none && !threadp
04550         && !declspecs->inline_p);
04551 
04552   /* Structure field.  It may not be a function.  */
04553 
04554   if (TREE_CODE (type) == FUNCTION_TYPE)
04555     {
04556       error ("field %qs declared as a function", name);
04557       type = build_pointer_type (type);
04558     }
04559   else if (TREE_CODE (type) != ERROR_MARK
04560            && !COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (type))
04561     {
04562       error ("field %qs has incomplete type", name);
04563       type = error_mark_node;
04564     }
04565   type = c_build_qualified_type (type, type_quals);
04566   decl = build_decl (FIELD_DECL, declarator->u.id, type);
04567   DECL_NONADDRESSABLE_P (decl) = bitfield;
04568 
04569   if (size_varies)
04570     C_DECL_VARIABLE_SIZE (decl) = 1;
04571       }
04572     else if (TREE_CODE (type) == FUNCTION_TYPE)
04573       {
04574   if (storage_class == csc_register || threadp)
04575     {
04576       error ("invalid storage class for function %qs", name);
04577      }
04578   else if (current_scope != file_scope)
04579     {
04580       /* Function declaration not at file scope.  Storage
04581          classes other than `extern' are not allowed, C99
04582          6.7.1p5, and `extern' makes no difference.  However,
04583          GCC allows 'auto', perhaps with 'inline', to support
04584          nested functions.  */
04585       if (storage_class == csc_auto)
04586         {
04587     if (pedantic)
04588       pedwarn ("invalid storage class for function %qs", name);
04589         }
04590       else if (storage_class == csc_static)
04591         {
04592           error ("invalid storage class for function %qs", name);
04593           if (funcdef_flag)
04594       storage_class = declspecs->storage_class = csc_none;
04595     else
04596       return 0;
04597         }
04598     }
04599 
04600   decl = build_decl (FUNCTION_DECL, declarator->u.id, type);
04601   decl = build_decl_attribute_variant (decl, decl_attr);
04602 
04603   DECL_LANG_SPECIFIC (decl) = GGC_CNEW (struct lang_decl);
04604 
04605   if (pedantic && type_quals && !DECL_IN_SYSTEM_HEADER (decl))
04606     pedwarn ("ISO C forbids qualified function types");
04607 
04608   /* GNU C interprets a volatile-qualified function type to indicate
04609      that the function does not return.  */
04610   if ((type_quals & TYPE_QUAL_VOLATILE)
04611       && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
04612     warning ("%<noreturn%> function returns non-void value");
04613 
04614   /* Every function declaration is an external reference
04615      (DECL_EXTERNAL) except for those which are not at file
04616      scope and are explicitly declared "auto".  This is
04617      forbidden by standard C (C99 6.7.1p5) and is interpreted by
04618      GCC to signify a forward declaration of a nested function.  */
04619   if (storage_class == csc_auto && current_scope != file_scope)
04620     DECL_EXTERNAL (decl) = 0;
04621   else
04622     DECL_EXTERNAL (decl) = 1;
04623 
04624   /* Record absence of global scope for `static' or `auto'.  */
04625   TREE_PUBLIC (decl)
04626     = !(storage_class == csc_static || storage_class == csc_auto);
04627 
04628   /* For a function definition, record the argument information
04629      block where store_parm_decls will look for it.  */
04630   if (funcdef_flag)
04631     current_function_arg_info = arg_info;
04632 
04633   if (declspecs->default_int_p)
04634     C_FUNCTION_IMPLICIT_INT (decl) = 1;
04635 
04636   /* Record presence of `inline', if it is reasonable.  */
04637   if (flag_hosted && MAIN_NAME_P (declarator->u.id))
04638     {
04639       if (declspecs->inline_p)
04640         pedwarn ("cannot inline function %<main%>");
04641     }
04642   else if (declspecs->inline_p)
04643     {
04644       /* Record that the function is declared `inline'.  */
04645       DECL_DECLARED_INLINE_P (decl) = 1;
04646 
04647       /* Do not mark bare declarations as DECL_INLINE.  Doing so
04648          in the presence of multiple declarations can result in
04649          the abstract origin pointing between the declarations,
04650          which will confuse dwarf2out.  */
04651       if (initialized)
04652         {
04653     DECL_INLINE (decl) = 1;
04654     if (storage_class == csc_extern)
04655       current_extern_inline = 1;
04656         }
04657     }
04658   /* If -finline-functions, assume it can be inlined.  This does
04659      two things: let the function be deferred until it is actually
04660      needed, and let dwarf2 know that the function is inlinable.  */
04661   else if (flag_inline_trees == 2 && initialized)
04662     DECL_INLINE (decl) = 1;
04663       }
04664     else
04665       {
04666   /* It's a variable.  */
04667   /* An uninitialized decl with `extern' is a reference.  */
04668   int extern_ref = !initialized && storage_class == csc_extern;
04669 
04670   type = c_build_qualified_type (type, type_quals);
04671 
04672   /* C99 6.2.2p7: It is invalid (compile-time undefined
04673      behavior) to create an 'extern' declaration for a
04674      variable if there is a global declaration that is
04675      'static' and the global declaration is not visible.
04676      (If the static declaration _is_ currently visible,
04677      the 'extern' declaration is taken to refer to that decl.) */
04678   if (extern_ref && current_scope != file_scope)
04679     {
04680       tree global_decl  = identifier_global_value (declarator->u.id);
04681       tree visible_decl = lookup_name (declarator->u.id);
04682 
04683       if (global_decl
04684     && global_decl != visible_decl
04685     && TREE_CODE (global_decl) == VAR_DECL
04686     && !TREE_PUBLIC (global_decl))
04687         error ("variable previously declared %<static%> redeclared "
04688          "%<extern%>");
04689     }
04690 
04691   decl = build_decl (VAR_DECL, declarator->u.id, type);
04692   if (size_varies)
04693     C_DECL_VARIABLE_SIZE (decl) = 1;
04694 
04695   if (declspecs->inline_p)
04696     pedwarn ("%Jvariable %qD declared %<inline%>", decl, decl);
04697 
04698   /* At file scope, an initialized extern declaration may follow
04699      a static declaration.  In that case, DECL_EXTERNAL will be
04700      reset later in start_decl.  */
04701   DECL_EXTERNAL (decl) = (storage_class == csc_extern);
04702 
04703   /* At file scope, the presence of a `static' or `register' storage
04704      class specifier, or the absence of all storage class specifiers
04705      makes this declaration a definition (perhaps tentative).  Also,
04706      the absence of both `static' and `register' makes it public.  */
04707   if (current_scope == file_scope)
04708     {
04709       TREE_PUBLIC (decl) = !(storage_class == csc_static
04710            || storage_class == csc_register);
04711       TREE_STATIC (decl) = !extern_ref;
04712     }
04713   /* Not at file scope, only `static' makes a static definition.  */
04714   else
04715     {
04716       TREE_STATIC (decl) = (storage_class == csc_static);
04717       TREE_PUBLIC (decl) = extern_ref;
04718     }
04719 
04720   if (threadp)
04721     {
04722       if (targetm.have_tls)
04723         DECL_THREAD_LOCAL (decl) = 1;
04724       else
04725         /* A mere warning is sure to result in improper semantics
04726      at runtime.  Don't bother to allow this to compile.  */
04727         error ("thread-local storage not supported for this target");
04728     }
04729       }
04730 
04731     /* Record `register' declaration for warnings on &
04732        and in case doing stupid register allocation.  */
04733 
04734     if (storage_class == csc_register)
04735       {
04736   C_DECL_REGISTER (decl) = 1;
04737   DECL_REGISTER (decl) = 1;
04738       }
04739 
04740     /* Record constancy and volatility.  */
04741     c_apply_type_quals_to_decl (type_quals, decl);
04742 
04743     /* If a type has volatile components, it should be stored in memory.
04744        Otherwise, the fact that those components are volatile
04745        will be ignored, and would even crash the compiler.  */
04746     if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl)))
04747       {
04748   /* It is not an error for a structure with volatile fields to
04749      be declared register, but reset DECL_REGISTER since it
04750      cannot actually go in a register.  */
04751   int was_reg = C_DECL_REGISTER (decl);
04752   C_DECL_REGISTER (decl) = 0;
04753   DECL_REGISTER (decl) = 0;
04754   c_mark_addressable (decl);
04755   C_DECL_REGISTER (decl) = was_reg;
04756       }
04757 
04758   /* This is the earliest point at which we might know the assembler
04759      name of a variable.  Thus, if it's known before this, die horribly.  */
04760     gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl));
04761 
04762     decl_attributes (&decl, returned_attrs, 0);
04763 
04764     return decl;
04765   }
04766 }
04767 
04768 /* Decode the parameter-list info for a function type or function definition.
04769    The argument is the value returned by `get_parm_info' (or made in parse.y
04770    if there is an identifier list instead of a parameter decl list).
04771    These two functions are separate because when a function returns
04772    or receives functions then each is called multiple times but the order
04773    of calls is different.  The last call to `grokparms' is always the one
04774    that contains the formal parameter names of a function definition.
04775 
04776    Return a list of arg types to use in the FUNCTION_TYPE for this function.
04777 
04778    FUNCDEF_FLAG is true for a function definition, false for
04779    a mere declaration.  A nonempty identifier-list gets an error message
04780    when FUNCDEF_FLAG is false.  */
04781 
04782 static tree
04783 grokparms (struct c_arg_info *arg_info, bool funcdef_flag)
04784 {
04785   tree arg_types = arg_info->types;
04786 
04787   if (warn_strict_prototypes && arg_types == 0 && !funcdef_flag
04788       && !in_system_header)
04789     warning ("function declaration isn%'t a prototype");
04790 
04791   if (arg_types == error_mark_node)
04792     return 0;  /* don't set TYPE_ARG_TYPES in this case */
04793 
04794   else if (arg_types && TREE_CODE (TREE_VALUE (arg_types)) == IDENTIFIER_NODE)
04795     {
04796       if (!funcdef_flag)
04797   pedwarn ("parameter names (without types) in function declaration");
04798 
04799       arg_info->parms = arg_info->types;
04800       arg_info->types = 0;
04801       return 0;
04802     }
04803   else
04804     {
04805       tree parm, type, typelt;
04806       unsigned int parmno;
04807 
04808       /* If there is a parameter of incomplete type in a definition,
04809    this is an error.  In a declaration this is valid, and a
04810    struct or union type may be completed later, before any calls
04811    or definition of the function.  In the case where the tag was
04812    first declared within the parameter list, a warning has
04813    already been given.  If a parameter has void type, then
04814    however the function cannot be defined or called, so
04815    warn.  */
04816 
04817       for (parm = arg_info->parms, typelt = arg_types, parmno = 1;
04818      parm;
04819      parm = TREE_CHAIN (parm), typelt = TREE_CHAIN (typelt), parmno++)
04820   {
04821     type = TREE_VALUE (typelt);
04822     if (type == error_mark_node)
04823       continue;
04824 
04825     if (!COMPLETE_TYPE_P (type))
04826       {
04827         if (funcdef_flag)
04828     {
04829       if (DECL_NAME (parm))
04830         error ("%Jparameter %u (%qD) has incomplete type",
04831          parm, parmno, parm);
04832       else
04833         error ("%Jparameter %u has incomplete type",
04834          parm, parmno);
04835 
04836       TREE_VALUE (typelt) = error_mark_node;
04837       TREE_TYPE (parm) = error_mark_node;
04838     }
04839         else if (VOID_TYPE_P (type))
04840     {
04841       if (DECL_NAME (parm))
04842         warning ("%Jparameter %u (%qD) has void type",
04843            parm, parmno, parm);
04844       else
04845         warning ("%Jparameter %u has void type",
04846            parm, parmno);
04847     }
04848       }
04849   }
04850       return arg_types;
04851     }
04852 }
04853 
04854 /* Take apart the current scope and return a c_arg_info structure with
04855    info on a parameter list just parsed.
04856 
04857    This structure is later fed to 'grokparms' and 'store_parm_decls'.
04858 
04859    ELLIPSIS being true means the argument list ended in '...' so don't
04860    append a sentinel (void_list_node) to the end of the type-list.  */
04861 
04862 struct c_arg_info *
04863 get_parm_info (bool ellipsis)
04864 {
04865   struct c_binding *b = current_scope->bindings;
04866   struct c_arg_info *arg_info = XOBNEW (&parser_obstack,
04867           struct c_arg_info);
04868   tree parms    = 0;
04869   tree tags     = 0;
04870   tree types    = 0;
04871   tree others   = 0;
04872 
04873   static bool explained_incomplete_types = false;
04874   bool gave_void_only_once_err = false;
04875 
04876   arg_info->parms = 0;
04877   arg_info->tags = 0;
04878   arg_info->types = 0;
04879   arg_info->others = 0;
04880 
04881   /* The bindings in this scope must not get put into a block.
04882      We will take care of deleting the binding nodes.  */
04883   current_scope->bindings = 0;
04884 
04885   /* This function is only called if there was *something* on the
04886      parameter list.  */
04887   gcc_assert (b);
04888 
04889   /* A parameter list consisting solely of 'void' indicates that the
04890      function takes no arguments.  But if the 'void' is qualified
04891      (by 'const' or 'volatile'), or has a storage class specifier
04892      ('register'), then the behavior is undefined; issue an error.
04893      Typedefs for 'void' are OK (see DR#157).  */
04894   if (b->prev == 0                /* one binding */
04895       && TREE_CODE (b->decl) == PARM_DECL   /* which is a parameter */
04896       && !DECL_NAME (b->decl)               /* anonymous */
04897       && VOID_TYPE_P (TREE_TYPE (b->decl))) /* of void type */
04898     {
04899       if (TREE_THIS_VOLATILE (b->decl)
04900     || TREE_READONLY (b->decl)
04901     || C_DECL_REGISTER (b->decl))
04902   error ("%<void%> as only parameter may not be qualified");
04903 
04904       /* There cannot be an ellipsis.  */
04905       if (ellipsis)
04906   error ("%<void%> must be the only parameter");
04907 
04908       arg_info->types = void_list_node;
04909       return arg_info;
04910     }
04911 
04912   if (!ellipsis)
04913     types = void_list_node;
04914 
04915   /* Break up the bindings list into parms, tags, types, and others;
04916      apply sanity checks; purge the name-to-decl bindings.  */
04917   while (b)
04918     {
04919       tree decl = b->decl;
04920       tree type = TREE_TYPE (decl);
04921       const char *keyword;
04922 
04923       switch (TREE_CODE (decl))
04924   {
04925   case PARM_DECL:
04926     if (b->id)
04927       {
04928         gcc_assert (I_SYMBOL_BINDING (b->id) == b);
04929         I_SYMBOL_BINDING (b->id) = b->shadowed;
04930       }
04931 
04932     /* Check for forward decls that never got their actual decl.  */
04933     if (TREE_ASM_WRITTEN (decl))
04934       error ("%Jparameter %qD has just a forward declaration",
04935        decl, decl);
04936     /* Check for (..., void, ...) and issue an error.  */
04937     else if (VOID_TYPE_P (type) && !DECL_NAME (decl))
04938       {
04939         if (!gave_void_only_once_err)
04940     {
04941       error ("%<void%> must be the only parameter");
04942       gave_void_only_once_err = true;
04943     }
04944       }
04945     else
04946       {
04947         /* Valid parameter, add it to the list.  */
04948         TREE_CHAIN (decl) = parms;
04949         parms = decl;
04950 
04951         /* Since there is a prototype, args are passed in their
04952      declared types.  The back end may override this later.  */
04953         DECL_ARG_TYPE (decl) = type;
04954         types = tree_cons (0, type, types);
04955       }
04956     break;
04957 
04958   case ENUMERAL_TYPE: keyword = "enum"; goto tag;
04959   case UNION_TYPE:    keyword = "union"; goto tag;
04960   case RECORD_TYPE:   keyword = "struct"; goto tag;
04961   tag:
04962     /* Types may not have tag-names, in which case the type
04963        appears in the bindings list with b->id NULL.  */
04964     if (b->id)
04965       {
04966         gcc_assert (I_TAG_BINDING (b->id) == b);
04967         I_TAG_BINDING (b->id) = b->shadowed;
04968       }
04969 
04970     /* Warn about any struct, union or enum tags defined in a
04971        parameter list.  The scope of such types is limited to
04972        the parameter list, which is rarely if ever desirable
04973        (it's impossible to call such a function with type-
04974        correct arguments).  An anonymous union parm type is
04975        meaningful as a GNU extension, so don't warn for that.  */
04976     if (TREE_CODE (decl) != UNION_TYPE || b->id != 0)
04977       {
04978         if (b->id)
04979     /* The %s will be one of 'struct', 'union', or 'enum'.  */
04980     warning ("%<%s %E%> declared inside parameter list",
04981        keyword, b->id);
04982         else
04983     /* The %s will be one of 'struct', 'union', or 'enum'.  */
04984     warning ("anonymous %s declared inside parameter list",
04985        keyword);
04986 
04987         if (!explained_incomplete_types)
04988     {
04989       warning ("its scope is only this definition or declaration,"
04990          " which is probably not what you want");
04991       explained_incomplete_types = true;
04992     }
04993       }
04994 
04995     tags = tree_cons (b->id, decl, tags);
04996     break;
04997 
04998   case CONST_DECL:
04999   case TYPE_DECL:
05000   case FUNCTION_DECL:
05001     /* CONST_DECLs appear here when we have an embedded enum,
05002        and TYPE_DECLs appear here when we have an embedded struct
05003        or union.  No warnings for this - we already warned about the
05004        type itself.  FUNCTION_DECLs appear when there is an implicit
05005        function declaration in the parameter list.  */
05006 
05007     TREE_CHAIN (decl) = others;
05008     others = decl;
05009     /* fall through */
05010 
05011   case ERROR_MARK:
05012     /* error_mark_node appears here when we have an undeclared
05013        variable.  Just throw it away.  */
05014     if (b->id)
05015       {
05016         gcc_assert (I_SYMBOL_BINDING (b->id) == b);
05017         I_SYMBOL_BINDING (b->id) = b->shadowed;
05018       }
05019     break;
05020 
05021     /* Other things that might be encountered.  */
05022   case LABEL_DECL:
05023   case VAR_DECL:
05024   default:
05025     gcc_unreachable ();
05026   }
05027 
05028       b = free_binding_and_advance (b);
05029     }
05030 
05031   arg_info->parms = parms;
05032   arg_info->tags = tags;
05033   arg_info->types = types;
05034   arg_info->others = others;
05035   return arg_info;
05036 }
05037 
05038 /* Get the struct, enum or union (CODE says which) with tag NAME.
05039    Define the tag as a forward-reference if it is not defined.
05040    Return a c_typespec structure for the type specifier.  */
05041 
05042 struct c_typespec
05043 parser_xref_tag (enum tree_code code, tree name)
05044 {
05045   struct c_typespec ret;
05046   /* If a cross reference is requested, look up the type
05047      already defined for this tag and return it.  */
05048 
05049   tree ref = lookup_tag (code, name, 0);
05050   /* If this is the right type of tag, return what we found.
05051      (This reference will be shadowed by shadow_tag later if appropriate.)
05052      If this is the wrong type of tag, do not return it.  If it was the
05053      wrong type in the same scope, we will have had an error
05054      message already; if in a different scope and declaring
05055      a name, pending_xref_error will give an error message; but if in a
05056      different scope and not declaring a name, this tag should
05057      shadow the previous declaration of a different type of tag, and
05058      this would not work properly if we return the reference found.
05059      (For example, with "struct foo" in an outer scope, "union foo;"
05060      must shadow that tag with a new one of union type.)  */
05061   ret.kind = (ref ? ctsk_tagref : ctsk_tagfirstref);
05062   if (ref && TREE_CODE (ref) == code)
05063     {
05064       ret.spec = ref;
05065       return ret;
05066     }
05067 
05068   /* If no such tag is yet defined, create a forward-reference node
05069      and record it as the "definition".
05070      When a real declaration of this type is found,
05071      the forward-reference will be altered into a real type.  */
05072 
05073   ref = make_node (code);
05074   if (code == ENUMERAL_TYPE)
05075     {
05076       /* Give the type a default layout like unsigned int
05077    to avoid crashing if it does not get defined.  */
05078       TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node);
05079       TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
05080       TYPE_USER_ALIGN (ref) = 0;
05081       TYPE_UNSIGNED (ref) = 1;
05082       TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
05083       TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
05084       TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
05085     }
05086 
05087   pushtag (name, ref);
05088 
05089   ret.spec = ref;
05090   return ret;
05091 }
05092 
05093 /* Get the struct, enum or union (CODE says which) with tag NAME.
05094    Define the tag as a forward-reference if it is not defined.
05095    Return a tree for the type.  */
05096 
05097 tree
05098 xref_tag (enum tree_code code, tree name)
05099 {
05100   return parser_xref_tag (code, name).spec;
05101 }
05102 
05103 /* Make sure that the tag NAME is defined *in the current scope*
05104    at least as a forward reference.
05105    CODE says which kind of tag NAME ought to be.  */
05106 
05107 tree
05108 start_struct (enum tree_code code, tree name)
05109 {
05110   /* If there is already a tag defined at this scope
05111      (as a forward reference), just return it.  */
05112 
05113   tree ref = 0;
05114 
05115   if (name != 0)
05116     ref = lookup_tag (code, name, 1);
05117   if (ref && TREE_CODE (ref) == code)
05118     {
05119       if (TYPE_SIZE (ref))
05120         {
05121     if (code == UNION_TYPE)
05122       error ("redefinition of %<union %s%>", IDENTIFIER_POINTER (name));
05123           else
05124       error ("redefinition of %<struct %s%>", IDENTIFIER_POINTER (name));
05125   }
05126       else if (C_TYPE_BEING_DEFINED (ref))
05127   {
05128     if (code == UNION_TYPE)
05129       error ("nested redefinition of %<union %s%>",
05130        IDENTIFIER_POINTER (name));
05131           else
05132       error ("nested redefinition of %<struct %s%>",
05133        IDENTIFIER_POINTER (name));
05134   }
05135     }
05136   else
05137     {
05138       /* Otherwise create a forward-reference just so the tag is in scope.  */
05139 
05140       ref = make_node (code);
05141       pushtag (name, ref);
05142     }
05143 
05144   C_TYPE_BEING_DEFINED (ref) = 1;
05145   TYPE_PACKED (ref) = flag_pack_struct;
05146   return ref;
05147 }
05148 
05149 /* Process the specs, declarator and width (NULL if omitted)
05150    of a structure component, returning a FIELD_DECL node.
05151    WIDTH is non-NULL for bit-fields only, and is an INTEGER_CST node.
05152 
05153    This is done during the parsing of the struct declaration.
05154    The FIELD_DECL nodes are chained together and the lot of them
05155    are ultimately passed to `build_struct' to make the RECORD_TYPE node.  */
05156 
05157 tree
05158 grokfield (struct c_declarator *declarator, struct c_declspecs *declspecs,
05159      tree width)
05160 {
05161   tree value;
05162 
05163   if (declarator->kind == cdk_id && declarator->u.id == NULL_TREE
05164       && width == NULL_TREE)
05165     {
05166       /* This is an unnamed decl.
05167 
05168    If we have something of the form "union { list } ;" then this
05169    is the anonymous union extension.  Similarly for struct.
05170 
05171    If this is something of the form "struct foo;", then
05172      If MS extensions are enabled, this is handled as an
05173        anonymous struct.
05174      Otherwise this is a forward declaration of a structure tag.
05175 
05176    If this is something of the form "foo;" and foo is a TYPE_DECL, then
05177      If MS extensions are enabled and foo names a structure, then
05178        again this is an anonymous struct.
05179      Otherwise this is an error.
05180 
05181    Oh what a horrid tangled web we weave.  I wonder if MS consciously
05182    took this from Plan 9 or if it was an accident of implementation
05183    that took root before someone noticed the bug...  */
05184 
05185       tree type = declspecs->type;
05186       bool type_ok = (TREE_CODE (type) == RECORD_TYPE
05187           || TREE_CODE (type) == UNION_TYPE);
05188       bool ok = false;
05189 
05190       if (type_ok
05191     && (flag_ms_extensions || !declspecs->typedef_p))
05192   {
05193     if (flag_ms_extensions)
05194       ok = true;
05195     else if (flag_iso)
05196       ok = false;
05197     else if (TYPE_NAME (type) == NULL)
05198       ok = true;
05199     else
05200       ok = false;
05201   }
05202       if (!ok)
05203   {
05204     pedwarn ("declaration does not declare anything");
05205     return NULL_TREE;
05206   }
05207       if (pedantic)
05208   pedwarn ("ISO C doesn%'t support unnamed structs/unions");
05209     }
05210 
05211   value = grokdeclarator (declarator, declspecs, FIELD, false,
05212         width ? &width : NULL);
05213 
05214   finish_decl (value, NULL_TREE, NULL_TREE);
05215   DECL_INITIAL (value) = width;
05216 
05217   return value;
05218 }
05219 
05220 /* Generate an error for any duplicate field names in FIELDLIST.  Munge
05221    the list such that this does not present a problem later.  */
05222 
05223 static void
05224 detect_field_duplicates (tree fieldlist)
05225 {
05226   tree x, y;
05227   int timeout = 10;
05228 
05229   /* First, see if there are more than "a few" fields.
05230      This is trivially true if there are zero or one fields.  */
05231   if (!fieldlist)
05232     return;
05233   x = TREE_CHAIN (fieldlist);
05234   if (!x)
05235     return;
05236   do {
05237     timeout--;
05238     x = TREE_CHAIN (x);
05239   } while (timeout > 0 && x);
05240 
05241   /* If there were "few" fields, avoid the overhead of allocating
05242      a hash table.  Instead just do the nested traversal thing.  */
05243   if (timeout > 0)
05244     {
05245       for (x = TREE_CHAIN (fieldlist); x ; x = TREE_CHAIN (x))
05246   if (DECL_NAME (x))
05247     {
05248       for (y = fieldlist; y != x; y = TREE_CHAIN (y))
05249         if (DECL_NAME (y) == DECL_NAME (x))
05250     {
05251       error ("%Jduplicate member %qD", x, x);
05252       DECL_NAME (x) = NULL_TREE;
05253     }
05254     }
05255     }
05256   else
05257     {
05258       htab_t htab = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
05259       void **slot;
05260 
05261       for (x = fieldlist; x ; x = TREE_CHAIN (x))
05262   if ((y = DECL_NAME (x)) != 0)
05263     {
05264       slot = htab_find_slot (htab, y, INSERT);
05265       if (*slot)
05266         {
05267     error ("%Jduplicate member %qD", x, x);
05268     DECL_NAME (x) = NULL_TREE;
05269         }
05270       *slot = y;
05271     }
05272 
05273       htab_delete (htab);
05274     }
05275 }
05276 
05277 /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
05278    FIELDLIST is a chain of FIELD_DECL nodes for the fields.
05279    ATTRIBUTES are attributes to be applied to the structure.  */
05280 
05281 tree
05282 finish_struct (tree t, tree fieldlist, tree attributes)
05283 {
05284   tree x;
05285   bool toplevel = file_scope == current_scope;
05286   int saw_named_field;
05287 
05288   /* If this type was previously laid out as a forward reference,
05289      make sure we lay it out again.  */
05290 
05291   TYPE_SIZE (t) = 0;
05292 
05293   decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
05294 
05295   if (pedantic)
05296     {
05297       for (x = fieldlist; x; x = TREE_CHAIN (x))
05298   if (DECL_NAME (x) != 0)
05299     break;
05300 
05301       if (x == 0)
05302   {
05303     if (TREE_CODE (t) == UNION_TYPE)
05304       {
05305         if (fieldlist)
05306     pedwarn ("union has no named members");
05307         else
05308     pedwarn ("union has no members");
05309       }
05310     else
05311       {
05312         if (fieldlist)
05313     pedwarn ("struct has no named members");
05314         else
05315     pedwarn ("struct has no members");
05316       }
05317   }
05318     }
05319 
05320   /* Install struct as DECL_CONTEXT of each field decl.
05321      Also process specified field sizes, found in the DECL_INITIAL,
05322      storing 0 there after the type has been changed to precision equal
05323      to its width, rather than the precision of the specified standard
05324      type.  (Correct layout requires the original type to have been preserved
05325      until now.)  */
05326 
05327   saw_named_field = 0;
05328   for (x = fieldlist; x; x = TREE_CHAIN (x))
05329     {
05330       DECL_CONTEXT (x) = t;
05331       DECL_PACKED (x) |= TYPE_PACKED (t);
05332 
05333       /* If any field is const, the structure type is pseudo-const.  */
05334       if (TREE_READONLY (x))
05335   C_TYPE_FIELDS_READONLY (t) = 1;
05336       else
05337   {
05338     /* A field that is pseudo-const makes the structure likewise.  */
05339     tree t1 = TREE_TYPE (x);
05340     while (TREE_CODE (t1) == ARRAY_TYPE)
05341       t1 = TREE_TYPE (t1);
05342     if ((TREE_CODE (t1) == RECORD_TYPE || TREE_CODE (t1) == UNION_TYPE)
05343         && C_TYPE_FIELDS_READONLY (t1))
05344       C_TYPE_FIELDS_READONLY (t) = 1;
05345   }
05346 
05347       /* Any field that is volatile means variables of this type must be
05348    treated in some ways as volatile.  */
05349       if (TREE_THIS_VOLATILE (x))
05350   C_TYPE_FIELDS_VOLATILE (t) = 1;
05351 
05352       /* Any field of nominal variable size implies structure is too.  */
05353       if (C_DECL_VARIABLE_SIZE (x))
05354   C_TYPE_VARIABLE_SIZE (t) = 1;
05355 
05356       if (DECL_INITIAL (x))
05357   {
05358     unsigned HOST_WIDE_INT width = tree_low_cst (DECL_INITIAL (x), 1);
05359     DECL_SIZE (x) = bitsize_int (width);
05360     DECL_BIT_FIELD (x) = 1;
05361     SET_DECL_C_BIT_FIELD (x);
05362   }
05363 
05364       /* Detect flexible array member in an invalid context.  */
05365       if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
05366     && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
05367     && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE
05368     && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE)
05369   {
05370     if (TREE_CODE (t) == UNION_TYPE)
05371       {
05372         error ("%Jflexible array member in union", x);
05373         TREE_TYPE (x) = error_mark_node;
05374       }
05375     else if (TREE_CHAIN (x) != NULL_TREE)
05376       {
05377         error ("%Jflexible array member not at end of struct", x);
05378         TREE_TYPE (x) = error_mark_node;
05379       }
05380     else if (!saw_named_field)
05381       {
05382         error ("%Jflexible array member in otherwise empty struct", x);
05383         TREE_TYPE (x) = error_mark_node;
05384       }
05385   }
05386 
05387       if (pedantic && !in_system_header && TREE_CODE (t) == RECORD_TYPE
05388     && flexible_array_type_p (TREE_TYPE (x)))
05389   pedwarn ("%Jinvalid use of structure with flexible array member", x);
05390 
05391       if (DECL_NAME (x))
05392   saw_named_field = 1;
05393     }
05394 
05395   detect_field_duplicates (fieldlist);
05396 
05397   /* Now we have the nearly final fieldlist.  Record it,
05398      then lay out the structure or union (including the fields).  */
05399 
05400   TYPE_FIELDS (t) = fieldlist;
05401 
05402   layout_type (t);
05403 
05404   /* Give bit-fields their proper types.  */
05405   {
05406     tree *fieldlistp = &fieldlist;
05407     while (*fieldlistp)
05408       if (TREE_CODE (*fieldlistp) == FIELD_DECL && DECL_INITIAL (*fieldlistp)
05409     && TREE_TYPE (*fieldlistp) != error_mark_node)
05410   {
05411     unsigned HOST_WIDE_INT width
05412       = tree_low_cst (DECL_INITIAL (*fieldlistp), 1);
05413     tree type = TREE_TYPE (*fieldlistp);
05414     if (width != TYPE_PRECISION (type))
05415       {
05416         TREE_TYPE (*fieldlistp)
05417     = c_build_bitfield_integer_type (width, TYPE_UNSIGNED (type));
05418         DECL_MODE (*fieldlistp) = TYPE_MODE (TREE_TYPE (*fieldlistp));
05419       }
05420     DECL_INITIAL (*fieldlistp) = 0;
05421   }
05422       else
05423   fieldlistp = &TREE_CHAIN (*fieldlistp);
05424   }
05425 
05426   /* Now we have the truly final field list.
05427      Store it in this type and in the variants.  */
05428 
05429   TYPE_FIELDS (t) = fieldlist;
05430 
05431   /* If there are lots of fields, sort so we can look through them fast.
05432      We arbitrarily consider 16 or more elts to be "a lot".  */
05433 
05434   {
05435     int len = 0;
05436 
05437     for (x = fieldlist; x; x = TREE_CHAIN (x))
05438       {
05439         if (len > 15 || DECL_NAME (x) == NULL)
05440           break;
05441         len += 1;
05442       }
05443 
05444     if (len > 15)
05445       {
05446         tree *field_array;
05447         struct lang_type *space;
05448         struct sorted_fields_type *space2;
05449 
05450         len += list_length (x);
05451 
05452         /* Use the same allocation policy here that make_node uses, to
05453           ensure that this lives as long as the rest of the struct decl.
05454           All decls in an inline function need to be saved.  */
05455 
05456         space = GGC_CNEW (struct lang_type);
05457         space2 = GGC_NEWVAR (struct sorted_fields_type,
05458            sizeof (struct sorted_fields_type) + len * sizeof (tree));
05459 
05460         len = 0;
05461   space->s = space2;
05462   field_array = &space2->elts[0];
05463         for (x = fieldlist; x; x = TREE_CHAIN (x))
05464           {
05465             field_array[len++] = x;
05466 
05467             /* If there is anonymous struct or union, break out of the loop.  */
05468             if (DECL_NAME (x) == NULL)
05469               break;
05470           }
05471         /* Found no anonymous struct/union.  Add the TYPE_LANG_SPECIFIC.  */
05472         if (x == NULL)
05473           {
05474             TYPE_LANG_SPECIFIC (t) = space;
05475             TYPE_LANG_SPECIFIC (t)->s->len = len;
05476             field_array = TYPE_LANG_SPECIFIC (t)->s->elts;
05477             qsort (field_array, len, sizeof (tree), field_decl_cmp);
05478           }
05479       }
05480   }
05481 
05482   for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
05483     {
05484       TYPE_FIELDS (x) = TYPE_FIELDS (t);
05485       TYPE_LANG_SPECIFIC (x) = TYPE_LANG_SPECIFIC (t);
05486       TYPE_ALIGN (x) = TYPE_ALIGN (t);
05487       TYPE_USER_ALIGN (x) = TYPE_USER_ALIGN (t);
05488       C_TYPE_FIELDS_READONLY (x) = C_TYPE_FIELDS_READONLY (t);
05489       C_TYPE_FIELDS_VOLATILE (x) = C_TYPE_FIELDS_VOLATILE (t);
05490       C_TYPE_VARIABLE_SIZE (x) = C_TYPE_VARIABLE_SIZE (t);
05491     }
05492 
05493   /* If this was supposed to be a transparent union, but we can't
05494      make it one, warn and turn off the flag.  */
05495   if (TREE_CODE (t) == UNION_TYPE
05496       && TYPE_TRANSPARENT_UNION (t)
05497       && (!TYPE_FIELDS (t) || TYPE_MODE (t) != DECL_MODE (TYPE_FIELDS (t))))
05498     {
05499       TYPE_TRANSPARENT_UNION (t) = 0;
05500       warning ("union cannot be made transparent");
05501     }
05502 
05503   /* If this structure or union completes the type of any previous
05504      variable declaration, lay it out and output its rtl.  */
05505   for (x = C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t));
05506        x;
05507        x = TREE_CHAIN (x))
05508     {
05509       tree decl = TREE_VALUE (x);
05510       if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
05511   layout_array_type (TREE_TYPE (decl));
05512       if (TREE_CODE (decl) != TYPE_DECL)
05513   {
05514     layout_decl (decl, 0);
05515     if (c_dialect_objc ())
05516       objc_check_decl (decl);
05517     rest_of_decl_compilation (decl, toplevel, 0);
05518     if (!toplevel)
05519       expand_decl (decl);
05520   }
05521     }
05522   C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t)) = 0;
05523 
05524   /* Finish debugging output for this type.  */
05525   rest_of_type_compilation (t, toplevel);
05526 
05527   /* If we're inside a function proper, i.e. not file-scope and not still
05528      parsing parameters, then arrange for the size of a variable sized type
05529      to be bound now.  */
05530   if (cur_stmt_list && variably_modified_type_p (t, NULL))
05531     add_stmt (build_stmt (DECL_EXPR, build_decl (TYPE_DECL, NULL, t)));
05532 
05533   return t;
05534 }
05535 
05536 /* Lay out the type T, and its element type, and so on.  */
05537 
05538 static void
05539 layout_array_type (tree t)
05540 {
05541   if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
05542     layout_array_type (TREE_TYPE (t));
05543   layout_type (t);
05544 }
05545 
05546 /* Begin compiling the definition of an enumeration type.
05547    NAME is its name (or null if anonymous).
05548    Returns the type object, as yet incomplete.
05549    Also records info about it so that build_enumerator
05550    may be used to declare the individual values as they are read.  */
05551 
05552 tree
05553 start_enum (tree name)
05554 {
05555   tree enumtype = 0;
05556 
05557   /* If this is the real definition for a previous forward reference,
05558      fill in the contents in the same object that used to be the
05559      forward reference.  */
05560 
05561   if (name != 0)
05562     enumtype = lookup_tag (ENUMERAL_TYPE, name, 1);
05563 
05564   if (enumtype == 0 || TREE_CODE (enumtype) != ENUMERAL_TYPE)
05565     {
05566       enumtype = make_node (ENUMERAL_TYPE);
05567       pushtag (name, enumtype);
05568     }
05569 
05570   if (C_TYPE_BEING_DEFINED (enumtype))
05571     error ("nested redefinition of %<enum %s%>", IDENTIFIER_POINTER (name));
05572 
05573   C_TYPE_BEING_DEFINED (enumtype) = 1;
05574 
05575   if (TYPE_VALUES (enumtype) != 0)
05576     {
05577       /* This enum is a named one that has been declared already.  */
05578       error ("redeclaration of %<enum %s%>", IDENTIFIER_POINTER (name));
05579 
05580       /* Completely replace its old definition.
05581    The old enumerators remain defined, however.  */
05582       TYPE_VALUES (enumtype) = 0;
05583     }
05584 
05585   enum_next_value = integer_zero_node;
05586   enum_overflow = 0;
05587 
05588   if (flag_short_enums)
05589     TYPE_PACKED (enumtype) = 1;
05590 
05591   return enumtype;
05592 }
05593 
05594 /* After processing and defining all the values of an enumeration type,
05595    install their decls in the enumeration type and finish it off.
05596    ENUMTYPE is the type object, VALUES a list of decl-value pairs,
05597    and ATTRIBUTES are the specified attributes.
05598    Returns ENUMTYPE.  */
05599 
05600 tree
05601 finish_enum (tree enumtype, tree values, tree attributes)
05602 {
05603   tree pair, tem;
05604   tree minnode = 0, maxnode = 0;
05605   int precision, unsign;
05606   bool toplevel = (file_scope == current_scope);
05607   struct lang_type *lt;
05608 
05609   decl_attributes (&enumtype, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
05610 
05611   /* Calculate the maximum value of any enumerator in this type.  */
05612 
05613   if (values == error_mark_node)
05614     minnode = maxnode = integer_zero_node;
05615   else
05616     {
05617       minnode = maxnode = TREE_VALUE (values);
05618       for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
05619   {
05620     tree value = TREE_VALUE (pair);
05621     if (tree_int_cst_lt (maxnode, value))
05622       maxnode = value;
05623     if (tree_int_cst_lt (value, minnode))
05624       minnode = value;
05625   }
05626     }
05627 
05628   /* Construct the final type of this enumeration.  It is the same
05629      as one of the integral types - the narrowest one that fits, except
05630      that normally we only go as narrow as int - and signed iff any of
05631      the values are negative.  */
05632   unsign = (tree_int_cst_sgn (minnode) >= 0);
05633   precision = MAX (min_precision (minnode, unsign),
05634        min_precision (maxnode, unsign));
05635 
05636   if (TYPE_PACKED (enumtype) || precision > TYPE_PRECISION (integer_type_node))
05637     {
05638       tem = c_common_type_for_size (precision, unsign);
05639       if (tem == NULL)
05640   {
05641 #ifdef TARG_SL
05642     if (Long_Long_Support == TRUE)
05643     {
05644       warning ("enumeration values exceed range of largest integer");
05645       tem = long_long_integer_type_node;
05646     }
05647     else
05648     {
05649       error("\"long long\" is mapped to \"long\", "
05650             "Please use \"-mlong-long\" option to enbale long long type suporting."
05651             "enumeration values exceed range of largest integer");
05652     }
05653 #else 
05654     warning ("enumeration values exceed range of largest integer");
05655     tem = long_long_integer_type_node;
05656 #endif
05657   }
05658     }
05659   else
05660     tem = unsign ? unsigned_type_node : integer_type_node;
05661 
05662   TYPE_MIN_VALUE (enumtype) = TYPE_MIN_VALUE (tem);
05663   TYPE_MAX_VALUE (enumtype) = TYPE_MAX_VALUE (tem);
05664   TYPE_UNSIGNED (enumtype) = TYPE_UNSIGNED (tem);
05665   TYPE_SIZE (enumtype) = 0;
05666 
05667   /* If the precision of the type was specific with an attribute and it
05668      was too small, give an error.  Otherwise, use it.  */
05669   if (TYPE_PRECISION (enumtype))
05670     {
05671       if (precision > TYPE_PRECISION (enumtype))
05672   error ("specified mode too small for enumeral values");
05673     }
05674   else
05675     TYPE_PRECISION (enumtype) = TYPE_PRECISION (tem);
05676 
05677   layout_type (enumtype);
05678 
05679   if (values != error_mark_node)
05680     {
05681       /* Change the type of the enumerators to be the enum type.  We
05682    need to do this irrespective of the size of the enum, for
05683    proper type checking.  Replace the DECL_INITIALs of the
05684    enumerators, and the value slots of the list, with copies
05685    that have the enum type; they cannot be modified in place
05686    because they may be shared (e.g.  integer_zero_node) Finally,
05687    change the purpose slots to point to the names of the decls.  */
05688       for (pair = values; pair; pair = TREE_CHAIN (pair))
05689   {
05690     tree enu = TREE_PURPOSE (pair);
05691     tree ini = DECL_INITIAL (enu);
05692 
05693     TREE_TYPE (enu) = enumtype;
05694 
05695     /* The ISO C Standard mandates enumerators to have type int,
05696        even though the underlying type of an enum type is
05697        unspecified.  Here we convert any enumerators that fit in
05698        an int to type int, to avoid promotions to unsigned types
05699        when comparing integers with enumerators that fit in the
05700        int range.  When -pedantic is given, build_enumerator()
05701        would have already taken care of those that don't fit.  */
05702     if (int_fits_type_p (ini, integer_type_node))
05703       tem = integer_type_node;
05704     else
05705       tem = enumtype;
05706     ini = convert (tem, ini);
05707 
05708     DECL_INITIAL (enu) = ini;
05709     TREE_PURPOSE (pair) = DECL_NAME (enu);
05710     TREE_VALUE (pair) = ini;
05711   }
05712 
05713       TYPE_VALUES (enumtype) = values;
05714     }
05715 
05716   /* Record the min/max values so that we can warn about bit-field
05717      enumerations that are too small for the values.  */
05718   lt = GGC_CNEW (struct lang_type);
05719   lt->enum_min = minnode;
05720   lt->enum_max = maxnode;
05721   TYPE_LANG_SPECIFIC (enumtype) = lt;
05722 
05723   /* Fix up all variant types of this enum type.  */
05724   for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem))
05725     {
05726       if (tem == enumtype)
05727   continue;
05728       TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
05729       TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
05730       TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
05731       TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
05732       TYPE_SIZE_UNIT (tem) = TYPE_SIZE_UNIT (enumtype);
05733       TYPE_MODE (tem) = TYPE_MODE (enumtype);
05734       TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
05735       TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype);
05736       TYPE_USER_ALIGN (tem) = TYPE_USER_ALIGN (enumtype);
05737       TYPE_UNSIGNED (tem) = TYPE_UNSIGNED (enumtype);
05738       TYPE_LANG_SPECIFIC (tem) = TYPE_LANG_SPECIFIC (enumtype);
05739     }
05740 
05741   /* Finish debugging output for this type.  */
05742   rest_of_type_compilation (enumtype, toplevel);
05743 
05744   return enumtype;
05745 }
05746 
05747 /* Build and install a CONST_DECL for one value of the
05748    current enumeration type (one that was begun with start_enum).
05749    Return a tree-list containing the CONST_DECL and its value.
05750    Assignment of sequential values by default is handled here.  */
05751 
05752 tree
05753 build_enumerator (tree name, tree value)
05754 {
05755   tree decl, type;
05756 
05757   /* Validate and default VALUE.  */
05758 
05759   /* Remove no-op casts from the value.  */
05760   if (value)
05761     STRIP_TYPE_NOPS (value);
05762 
05763   if (value != 0)
05764     {
05765       /* Don't issue more errors for error_mark_node (i.e. an
05766    undeclared identifier) - just ignore the value expression.  */
05767       if (value == error_mark_node)
05768   value = 0;
05769       else if (!INTEGRAL_TYPE_P (TREE_TYPE (value))
05770          || TREE_CODE (value) != INTEGER_CST)
05771   {
05772     error ("enumerator value for %qE is not an integer constant", name);
05773     value = 0;
05774   }
05775       else
05776   {
05777     value = default_conversion (value);
05778     constant_expression_warning (value);
05779   }
05780     }
05781 
05782   /* Default based on previous value.  */
05783   /* It should no longer be possible to have NON_LVALUE_EXPR
05784      in the default.  */
05785   if (value == 0)
05786     {
05787       value = enum_next_value;
05788       if (enum_overflow)
05789   error ("overflow in enumeration values");
05790     }
05791 
05792   if (pedantic && !int_fits_type_p (value, integer_type_node))
05793     {
05794       pedwarn ("ISO C restricts enumerator values to range of %<int%>");
05795       /* XXX This causes -pedantic to change the meaning of the program.
05796    Remove?  -zw 2004-03-15  */
05797       value = convert (integer_type_node, value);
05798     }
05799 
05800   /* Set basis for default for next value.  */
05801   enum_next_value = build_binary_op (PLUS_EXPR, value, integer_one_node, 0);
05802   enum_overflow = tree_int_cst_lt (enum_next_value, value);
05803 
05804   /* Now create a declaration for the enum value name.  */
05805 
05806   type = TREE_TYPE (value);
05807   type = c_common_type_for_size (MAX (TYPE_PRECISION (type),
05808               TYPE_PRECISION (integer_type_node)),
05809          (TYPE_PRECISION (type)
05810           >= TYPE_PRECISION (integer_type_node)
05811           && TYPE_UNSIGNED (type)));
05812 
05813   decl = build_decl (CONST_DECL, name, type);
05814   DECL_INITIAL (decl) = convert (type, value);
05815   pushdecl (decl);
05816 
05817   return tree_cons (decl, value, NULL_TREE);
05818 }
05819 
05820 
05821 /* Create the FUNCTION_DECL for a function definition.
05822    DECLSPECS, DECLARATOR and ATTRIBUTES are the parts of
05823    the declaration; they describe the function's name and the type it returns,
05824    but twisted together in a fashion that parallels the syntax of C.
05825 
05826    This function creates a binding context for the function body
05827    as well as setting up the FUNCTION_DECL in current_function_decl.
05828 
05829    Returns 1 on success.  If the DECLARATOR is not suitable for a function
05830    (it defines a datum instead), we return 0, which tells
05831    yyparse to report a parse error.  */
05832 
05833 int
05834 start_function (struct c_declspecs *declspecs, struct c_declarator *declarator,
05835     tree attributes)
05836 {
05837   tree decl1, old_decl;
05838   tree restype, resdecl;
05839   struct c_label_context_se *nstack_se;
05840   struct c_label_context_vm *nstack_vm;
05841 
05842   current_function_returns_value = 0;  /* Assume, until we see it does.  */
05843   current_function_returns_null = 0;
05844   current_function_returns_abnormally = 0;
05845   warn_about_return_type = 0;
05846   current_extern_inline = 0;
05847   c_switch_stack = NULL;
05848 
05849   nstack_se = XOBNEW (&parser_obstack, struct c_label_context_se);
05850   nstack_se->labels_def = NULL;
05851   nstack_se->labels_used = NULL;
05852   nstack_se->next = label_context_stack_se;
05853   label_context_stack_se = nstack_se;
05854 
05855   nstack_vm = XOBNEW (&parser_obstack, struct c_label_context_vm);
05856   nstack_vm->labels_def = NULL;
05857   nstack_vm->labels_used = NULL;
05858   nstack_vm->scope = 0;
05859   nstack_vm->next = label_context_stack_vm;
05860   label_context_stack_vm = nstack_vm;
05861 
05862   /* Indicate no valid break/continue context by setting these variables
05863      to some non-null, non-label value.  We'll notice and emit the proper
05864      error message in c_finish_bc_stmt.  */
05865   c_break_label = c_cont_label = size_zero_node;
05866 
05867   decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, true, NULL);
05868 
05869   /* If the declarator is not suitable for a function definition,
05870      cause a syntax error.  */
05871   if (decl1 == 0)
05872     {
05873       label_context_stack_se = label_context_stack_se->next;
05874       label_context_stack_vm = label_context_stack_vm->next;
05875       return 0;
05876     }
05877 
05878   decl_attributes (&decl1, attributes, 0);
05879 
05880   if (DECL_DECLARED_INLINE_P (decl1)
05881       && DECL_UNINLINABLE (decl1)
05882       && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl1)))
05883     warning ("%Jinline function %qD given attribute noinline", decl1, decl1);
05884 
05885   announce_function (decl1);
05886 
05887   if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl1))))
05888     {
05889       error ("return type is an incomplete type");
05890       /* Make it return void instead.  */
05891       TREE_TYPE (decl1)
05892   = build_function_type (void_type_node,
05893              TYPE_ARG_TYPES (TREE_TYPE (decl1)));
05894     }
05895 
05896   if (warn_about_return_type)
05897     pedwarn_c99 ("return type defaults to %<int%>");
05898 
05899   /* Make the init_value nonzero so pushdecl knows this is not tentative.
05900      error_mark_node is replaced below (in pop_scope) with the BLOCK.  */
05901   DECL_INITIAL (decl1) = error_mark_node;
05902 
05903   /* If this definition isn't a prototype and we had a prototype declaration
05904      before, copy the arg type info from that prototype.  */
05905   old_decl = lookup_name_in_scope (DECL_NAME (decl1), current_scope);
05906   current_function_prototype_locus = UNKNOWN_LOCATION;
05907   current_function_prototype_built_in = false;
05908   current_function_prototype_arg_types = NULL_TREE;
05909   if (TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0)
05910     {
05911       if (old_decl != 0 && TREE_CODE (TREE_TYPE (old_decl)) == FUNCTION_TYPE
05912     && comptypes (TREE_TYPE (TREE_TYPE (decl1)),
05913       TREE_TYPE (TREE_TYPE (old_decl))))
05914   {
05915     TREE_TYPE (decl1) = composite_type (TREE_TYPE (old_decl),
05916                 TREE_TYPE (decl1));
05917     current_function_prototype_locus = DECL_SOURCE_LOCATION (old_decl);
05918     current_function_prototype_built_in
05919       = C_DECL_BUILTIN_PROTOTYPE (old_decl);
05920     current_function_prototype_arg_types
05921       = TYPE_ARG_TYPES (TREE_TYPE (decl1));
05922   }
05923       if (TREE_PUBLIC (decl1))
05924   {
05925     /* If there is an external prototype declaration of this
05926        function, record its location but do not copy information
05927        to this decl.  This may be an invisible declaration
05928        (built-in or in a scope which has finished) or simply
05929        have more refined argument types than any declaration
05930        found above.  */
05931     struct c_binding *b;
05932     for (b = I_SYMBOL_BINDING (DECL_NAME (decl1)); b; b = b->shadowed)
05933       if (B_IN_SCOPE (b, external_scope))
05934         break;
05935     if (b)
05936       {
05937         tree ext_decl, ext_type;
05938         ext_decl = b->decl;
05939         ext_type = b->type ? b->type : TREE_TYPE (ext_decl);
05940         if (TREE_CODE (ext_type) == FUNCTION_TYPE
05941       && comptypes (TREE_TYPE (TREE_TYPE (decl1)),
05942         TREE_TYPE (ext_type)))
05943     {
05944       current_function_prototype_locus
05945         = DECL_SOURCE_LOCATION (ext_decl);
05946       current_function_prototype_built_in
05947         = C_DECL_BUILTIN_PROTOTYPE (ext_decl);
05948       current_function_prototype_arg_types
05949         = TYPE_ARG_TYPES (ext_type);
05950     }
05951       }
05952   }
05953     }
05954 
05955   /* Optionally warn of old-fashioned def with no previous prototype.  */
05956   if (warn_strict_prototypes
05957       && old_decl != error_mark_node
05958       && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0
05959       && C_DECL_ISNT_PROTOTYPE (old_decl))
05960     warning ("function declaration isn%'t a prototype");
05961   /* Optionally warn of any global def with no previous prototype.  */
05962   else if (warn_missing_prototypes
05963      && old_decl != error_mark_node
05964      && TREE_PUBLIC (decl1)
05965      && !MAIN_NAME_P (DECL_NAME (decl1))
05966      && C_DECL_ISNT_PROTOTYPE (old_decl))
05967     warning ("%Jno previous prototype for %qD", decl1, decl1);
05968   /* Optionally warn of any def with no previous prototype
05969      if the function has already been used.  */
05970   else if (warn_missing_prototypes
05971      && old_decl != 0
05972      && old_decl != error_mark_node
05973      && TREE_USED (old_decl)
05974      && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) == 0)
05975     warning ("%J%qD was used with no prototype before its definition",
05976        decl1, decl1);
05977   /* Optionally warn of any global def with no previous declaration.  */
05978   else if (warn_missing_declarations
05979      && TREE_PUBLIC (decl1)
05980      && old_decl == 0
05981      && !MAIN_NAME_P (DECL_NAME (decl1)))
05982     warning ("%Jno previous declaration for %qD", decl1, decl1);
05983   /* Optionally warn of any def with no previous declaration
05984      if the function has already been used.  */
05985   else if (warn_missing_declarations
05986      && old_decl != 0
05987      && old_decl != error_mark_node
05988      && TREE_USED (old_decl)
05989      && C_DECL_IMPLICIT (old_decl))
05990     warning ("%J%qD was used with no declaration before its definition",
05991        decl1, decl1);
05992 
05993   /* This is a definition, not a reference.
05994      So normally clear DECL_EXTERNAL.
05995      However, `extern inline' acts like a declaration
05996      except for defining how to inline.  So set DECL_EXTERNAL in that case.  */
05997   DECL_EXTERNAL (decl1) = current_extern_inline;
05998 
05999   /* This function exists in static storage.
06000      (This does not mean `static' in the C sense!)  */
06001   TREE_STATIC (decl1) = 1;
06002 
06003   /* A nested function is not global.  */
06004   if (current_function_decl != 0)
06005     TREE_PUBLIC (decl1) = 0;
06006 
06007   /* This is the earliest point at which we might know the assembler
06008      name of the function.  Thus, if it's set before this, die horribly.  */
06009   gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl1));
06010 
06011   /* If #pragma weak was used, mark the decl weak now.  */
06012   if (current_scope == file_scope)
06013     maybe_apply_pragma_weak (decl1);
06014 
06015   /* Warn for unlikely, improbable, or stupid declarations of `main'.  */
06016   if (warn_main > 0 && MAIN_NAME_P (DECL_NAME (decl1)))
06017     {
06018       tree args;
06019       int argct = 0;
06020 
06021       if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
06022     != integer_type_node)
06023   pedwarn ("%Jreturn type of %qD is not %<int%>", decl1, decl1);
06024 
06025       for (args = TYPE_ARG_TYPES (TREE_TYPE (decl1)); args;
06026      args = TREE_CHAIN (args))
06027   {
06028     tree type = args ? TREE_VALUE (args) : 0;
06029 
06030     if (type == void_type_node)
06031       break;
06032 
06033     ++argct;
06034     switch (argct)
06035       {
06036       case 1:
06037         if (TYPE_MAIN_VARIANT (type) != integer_type_node)
06038     pedwarn ("%Jfirst argument of %qD should be %<int%>",
06039        decl1, decl1);
06040         break;
06041 
06042       case 2:
06043         if (TREE_CODE (type) != POINTER_TYPE
06044       || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
06045       || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
06046           != char_type_node))
06047     pedwarn ("%Jsecond argument of %qD should be %<char **%>",
06048                          decl1, decl1);
06049         break;
06050 
06051       case 3:
06052         if (TREE_CODE (type) != POINTER_TYPE
06053       || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
06054       || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
06055           != char_type_node))
06056     pedwarn ("%Jthird argument of %qD should probably be "
06057                          "%<char **%>", decl1, decl1);
06058         break;
06059       }
06060   }
06061 
06062       /* It is intentional that this message does not mention the third
06063    argument because it's only mentioned in an appendix of the
06064    standard.  */
06065       if (argct > 0 && (argct < 2 || argct > 3))
06066   pedwarn ("%J%qD takes only zero or two arguments", decl1, decl1);
06067 
06068       if (!TREE_PUBLIC (decl1))
06069   pedwarn ("%J%qD is normally a non-static function", decl1, decl1);
06070     }
06071 
06072   /* Record the decl so that the function name is defined.
06073      If we already have a decl for this name, and it is a FUNCTION_DECL,
06074      use the old decl.  */
06075 
06076   current_function_decl = pushdecl (decl1);
06077 
06078   push_scope ();
06079   declare_parm_level ();
06080 
06081   restype = TREE_TYPE (TREE_TYPE (current_function_decl));
06082   /* Promote the value to int before returning it.  */
06083   if (c_promoting_integer_type_p (restype))
06084     {
06085       /* It retains unsignedness if not really getting wider.  */
06086       if (TYPE_UNSIGNED (restype)
06087     && (TYPE_PRECISION (restype)
06088       == TYPE_PRECISION (integer_type_node)))
06089   restype = unsigned_type_node;
06090       else
06091   restype = integer_type_node;
06092     }
06093 
06094   resdecl = build_decl (RESULT_DECL, NULL_TREE, restype);
06095   DECL_ARTIFICIAL (resdecl) = 1;
06096   DECL_IGNORED_P (resdecl) = 1;
06097   DECL_RESULT (current_function_decl) = resdecl;
06098 
06099   start_fname_decls ();
06100 
06101   return 1;
06102 }
06103 
06104 /* Subroutine of store_parm_decls which handles new-style function
06105    definitions (prototype format). The parms already have decls, so we
06106    need only record them as in effect and complain if any redundant
06107    old-style parm decls were written.  */
06108 static void
06109 store_parm_decls_newstyle (tree fndecl, const struct c_arg_info *arg_info)
06110 {
06111   tree decl;
06112 
06113   if (current_scope->bindings)
06114     {
06115       error ("%Jold-style parameter declarations in prototyped "
06116        "function definition", fndecl);
06117 
06118       /* Get rid of the old-style declarations.  */
06119       pop_scope ();
06120       push_scope ();
06121     }
06122   /* Don't issue this warning for nested functions, and don't issue this
06123      warning if we got here because ARG_INFO_TYPES was error_mark_node
06124      (this happens when a function definition has just an ellipsis in
06125      its parameter list).  */
06126   else if (warn_traditional && !in_system_header && !current_function_scope
06127      && arg_info->types != error_mark_node)
06128     warning ("%Jtraditional C rejects ISO C style function definitions",
06129        fndecl);
06130 
06131   /* Now make all the parameter declarations visible in the function body.
06132      We can bypass most of the grunt work of pushdecl.  */
06133   for (decl = arg_info->parms; decl; decl = TREE_CHAIN (decl))
06134     {
06135       DECL_CONTEXT (decl) = current_function_decl;
06136       if (DECL_NAME (decl))
06137   bind (DECL_NAME (decl), decl, current_scope,
06138         /*invisible=*/false, /*nested=*/false);
06139       else
06140   error ("%Jparameter name omitted", decl);
06141     }
06142 
06143   /* Record the parameter list in the function declaration.  */
06144   DECL_ARGUMENTS (fndecl) = arg_info->parms;
06145 
06146   /* Now make all the ancillary declarations visible, likewise.  */
06147   for (decl = arg_info->others; decl; decl = TREE_CHAIN (decl))
06148     {
06149       DECL_CONTEXT (decl) = current_function_decl;
06150       if (DECL_NAME (decl))
06151   bind (DECL_NAME (decl), decl, current_scope,
06152         /*invisible=*/false, /*nested=*/false);
06153     }
06154 
06155   /* And all the tag declarations.  */
06156   for (decl = arg_info->tags; decl; decl = TREE_CHAIN (decl))
06157     if (TREE_PURPOSE (decl))
06158       bind (TREE_PURPOSE (decl), TREE_VALUE (decl), current_scope,
06159       /*invisible=*/false, /*nested=*/false);
06160 }
06161 
06162 /* Subroutine of store_parm_decls which handles old-style function
06163    definitions (separate parameter list and declarations).  */
06164 
06165 static void
06166 store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info)
06167 {
06168   struct c_binding *b;
06169   tree parm, decl, last;
06170   tree parmids = arg_info->parms;
06171 
06172   /* We use DECL_WEAK as a flag to show which parameters have been
06173      seen already, since it is not used on PARM_DECL.  */
06174 #ifdef ENABLE_CHECKING
06175   for (b = current_scope->bindings; b; b = b->prev)
06176     gcc_assert (TREE_CODE (b->decl) != PARM_DECL || !DECL_WEAK (b->decl));
06177 #endif
06178 
06179 #ifdef TARG_SL
06180 /* Don't support old-style function definition for float/double type */
06181     tree parm_t;
06182     int float_flag = 0;
06183     for (parm_t = parmids; parm_t != NULL; parm_t = TREE_CHAIN(parm_t))
06184     {
06185         tree type_node = TYPE_MAIN_VARIANT(TREE_TYPE((I_SYMBOL_BINDING (TREE_VALUE (parm_t))->decl)));
06186         if (type_node == float_type_node || type_node == double_type_node) 
06187         {
06188             float_flag = 1;
06189             break;
06190         }
06191     }
06192     if (float_flag == 1)
06193     {
06194        error("Old-style function definition is not supported for float/double type");
06195     }
06196     else
06197     {
06198        warning("Old-style function definition");
06199     }
06200 #endif
06201 
06202   if (warn_old_style_definition && !in_system_header)
06203     warning ("%Jold-style function definition", fndecl);
06204 
06205   /* Match each formal parameter name with its declaration.  Save each
06206      decl in the appropriate TREE_PURPOSE slot of the parmids chain.  */
06207   for (parm = parmids; parm; parm = TREE_CHAIN (parm))
06208     {
06209       if (TREE_VALUE (parm) == 0)
06210   {
06211     error ("%Jparameter name missing from parameter list", fndecl);
06212     TREE_PURPOSE (parm) = 0;
06213     continue;
06214   }
06215 
06216       b = I_SYMBOL_BINDING (TREE_VALUE (parm));
06217       if (b && B_IN_CURRENT_SCOPE (b))
06218   {
06219     decl = b->decl;
06220     /* If we got something other than a PARM_DECL it is an error.  */
06221     if (TREE_CODE (decl) != PARM_DECL)
06222       error ("%J%qD declared as a non-parameter", decl, decl);
06223     /* If the declaration is already marked, we have a duplicate
06224        name.  Complain and ignore the duplicate.  */
06225     else if (DECL_WEAK (decl))
06226       {
06227         error ("%Jmultiple parameters named %qD", decl, decl);
06228         TREE_PURPOSE (parm) = 0;
06229         continue;
06230       }
06231     /* If the declaration says "void", complain and turn it into
06232        an int.  */
06233     else if (VOID_TYPE_P (TREE_TYPE (decl)))
06234       {
06235         error ("%Jparameter %qD declared with void type", decl, decl);
06236         TREE_TYPE (decl) = integer_type_node;
06237         DECL_ARG_TYPE (decl) = integer_type_node;
06238         layout_decl (decl, 0);
06239       }
06240   }
06241       /* If no declaration found, default to int.  */
06242       else
06243   {
06244     decl = build_decl (PARM_DECL, TREE_VALUE (parm), integer_type_node);
06245     DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
06246     DECL_SOURCE_LOCATION (decl) = DECL_SOURCE_LOCATION (fndecl);
06247     pushdecl (decl);
06248 
06249     if (flag_isoc99)
06250       pedwarn ("%Jtype of %qD defaults to %<int%>", decl, decl);
06251     else if (extra_warnings)
06252       warning ("%Jtype of %qD defaults to %<int%>", decl, decl);
06253   }
06254 
06255       TREE_PURPOSE (parm) = decl;
06256       DECL_WEAK (decl) = 1;
06257     }
06258 
06259   /* Now examine the parms chain for incomplete declarations
06260      and declarations with no corresponding names.  */
06261 
06262   for (b = current_scope->bindings; b; b = b->prev)
06263     {
06264       parm = b->decl;
06265       if (TREE_CODE (parm) != PARM_DECL)
06266   continue;
06267 
06268       if (TREE_TYPE (parm) != error_mark_node
06269     && !COMPLETE_TYPE_P (TREE_TYPE (parm)))
06270   {
06271     error ("%Jparameter %qD has incomplete type", parm, parm);
06272     TREE_TYPE (parm) = error_mark_node;
06273   }
06274 
06275       if (!DECL_WEAK (parm))
06276   {
06277     error ("%Jdeclaration for parameter %qD but no such parameter",
06278      parm, parm);
06279 
06280     /* Pretend the parameter was not missing.
06281        This gets us to a standard state and minimizes
06282        further error messages.  */
06283     parmids = chainon (parmids, tree_cons (parm, 0, 0));
06284   }
06285     }
06286 
06287   /* Chain the declarations together in the order of the list of
06288      names.  Store that chain in the function decl, replacing the
06289      list of names.  Update the current scope to match.  */
06290   DECL_ARGUMENTS (fndecl) = 0;
06291 
06292   for (parm = parmids; parm; parm = TREE_CHAIN (parm))
06293     if (TREE_PURPOSE (parm))
06294       break;
06295   if (parm && TREE_PURPOSE (parm))
06296     {
06297       last = TREE_PURPOSE (parm);
06298       DECL_ARGUMENTS (fndecl) = last;
06299       DECL_WEAK (last) = 0;
06300 
06301       for (parm = TREE_CHAIN (parm); parm; parm = TREE_CHAIN (parm))
06302   if (TREE_PURPOSE (parm))
06303     {
06304       TREE_CHAIN (last) = TREE_PURPOSE (parm);
06305       last = TREE_PURPOSE (parm);
06306       DECL_WEAK (last) = 0;
06307     }
06308       TREE_CHAIN (last) = 0;
06309     }
06310 
06311   /* If there was a previous prototype,
06312      set the DECL_ARG_TYPE of each argument according to
06313      the type previously specified, and report any mismatches.  */
06314 
06315   if (current_function_prototype_arg_types)
06316     {
06317       tree type;
06318       for (parm = DECL_ARGUMENTS (fndecl),
06319        type = current_function_prototype_arg_types;
06320      parm || (type && (TYPE_MAIN_VARIANT (TREE_VALUE (type))
06321            != void_type_node));
06322      parm = TREE_CHAIN (parm), type = TREE_CHAIN (type))
06323   {
06324     if (parm == 0 || type == 0
06325         || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
06326       {
06327         if (current_function_prototype_built_in)
06328     warning ("number of arguments doesn%'t match "
06329        "built-in prototype");
06330         else
06331     {
06332       error ("number of arguments doesn%'t match prototype");
06333       error ("%Hprototype declaration",
06334        &current_function_prototype_locus);
06335     }
06336         break;
06337       }
06338     /* Type for passing arg must be consistent with that
06339        declared for the arg.  ISO C says we take the unqualified
06340        type for parameters declared with qualified type.  */
06341     if (!comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm)),
06342         TYPE_MAIN_VARIANT (TREE_VALUE (type))))
06343       {
06344         if (TYPE_MAIN_VARIANT (TREE_TYPE (parm))
06345       == TYPE_MAIN_VARIANT (TREE_VALUE (type)))
06346     {
06347       /* Adjust argument to match prototype.  E.g. a previous
06348          `int foo(float);' prototype causes
06349          `int foo(x) float x; {...}' to be treated like
06350          `int foo(float x) {...}'.  This is particularly
06351          useful for argument types like uid_t.  */
06352       DECL_ARG_TYPE (parm) = TREE_TYPE (parm);
06353 
06354       if (targetm.calls.promote_prototypes (TREE_TYPE (current_function_decl))
06355           && INTEGRAL_TYPE_P (TREE_TYPE (parm))
06356           && TYPE_PRECISION (TREE_TYPE (parm))
06357           < TYPE_PRECISION (integer_type_node))
06358         DECL_ARG_TYPE (parm) = integer_type_node;
06359 
06360       if (pedantic)
06361         {
06362           /* ??? Is it possible to get here with a
06363        built-in prototype or will it always have
06364        been diagnosed as conflicting with an
06365        old-style definition and discarded?  */
06366           if (current_function_prototype_built_in)
06367       warning ("promoted argument %qD "
06368          "doesn%'t match built-in prototype", parm);
06369           else
06370       {
06371         pedwarn ("promoted argument %qD "
06372            "doesn%'t match prototype", parm);
06373         pedwarn ("%Hprototype declaration",
06374            &current_function_prototype_locus);
06375       }
06376         }
06377     }
06378         else
06379     {
06380       if (current_function_prototype_built_in)
06381         warning ("argument %qD doesn%'t match "
06382            "built-in prototype", parm);
06383       else
06384         {
06385           error ("argument %qD doesn%'t match prototype", parm);
06386           error ("%Hprototype declaration",
06387            &current_function_prototype_locus);
06388         }
06389     }
06390       }
06391   }
06392       TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = 0;
06393     }
06394 
06395   /* Otherwise, create a prototype that would match.  */
06396 
06397   else
06398     {
06399       tree actual = 0, last = 0, type;
06400 
06401       for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm))
06402   {
06403     type = tree_cons (NULL_TREE, DECL_ARG_TYPE (parm), NULL_TREE);
06404     if (last)
06405       TREE_CHAIN (last) = type;
06406     else
06407       actual = type;
06408     last = type;
06409   }
06410       type = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
06411       if (last)
06412   TREE_CHAIN (last) = type;
06413       else
06414   actual = type;
06415 
06416       /* We are going to assign a new value for the TYPE_ACTUAL_ARG_TYPES
06417    of the type of this function, but we need to avoid having this
06418    affect the types of other similarly-typed functions, so we must
06419    first force the generation of an identical (but separate) type
06420    node for the relevant function type.  The new node we create
06421    will be a variant of the main variant of the original function
06422    type.  */
06423 
06424       TREE_TYPE (fndecl) = build_variant_type_copy (TREE_TYPE (fndecl));
06425 
06426       TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = actual;
06427     }
06428 }
06429 
06430 /* Store parameter declarations passed in ARG_INFO into the current
06431    function declaration.  */
06432 
06433 void
06434 store_parm_decls_from (struct c_arg_info *arg_info)
06435 {
06436   current_function_arg_info = arg_info;
06437   store_parm_decls ();
06438 }
06439 
06440 /* Store the parameter declarations into the current function declaration.
06441    This is called after parsing the parameter declarations, before
06442    digesting the body of the function.
06443 
06444    For an old-style definition, construct a prototype out of the old-style
06445    parameter declarations and inject it into the function's type.  */
06446 
06447 void
06448 store_parm_decls (void)
06449 {
06450   tree fndecl = current_function_decl;
06451   bool proto;
06452 
06453   /* The argument information block for FNDECL.  */
06454   struct c_arg_info *arg_info = current_function_arg_info;
06455   current_function_arg_info = 0;
06456 
06457   /* True if this definition is written with a prototype.  Note:
06458      despite C99 6.7.5.3p14, we can *not* treat an empty argument
06459      list in a function definition as equivalent to (void) -- an
06460      empty argument list specifies the function has no parameters,
06461      but only (void) sets up a prototype for future calls.  */
06462   proto = arg_info->types != 0;
06463 
06464   if (proto)
06465     store_parm_decls_newstyle (fndecl, arg_info);
06466   else
06467     store_parm_decls_oldstyle (fndecl, arg_info);
06468 
06469   /* The next call to push_scope will be a function body.  */
06470 
06471   next_is_function_body = true;
06472 
06473   /* Write a record describing this function definition to the prototypes
06474      file (if requested).  */
06475 
06476   gen_aux_info_record (fndecl, 1, 0, proto);
06477 
06478   /* Initialize the RTL code for the function.  */
06479   allocate_struct_function (fndecl);
06480 
06481   /* Begin the statement tree for this function.  */
06482   DECL_SAVED_TREE (fndecl) = push_stmt_list ();
06483 
06484   /* ??? Insert the contents of the pending sizes list into the function
06485      to be evaluated.  The only reason left to have this is
06486   void foo(int n, int array[n++])
06487      because we throw away the array type in favor of a pointer type, and
06488      thus won't naturally see the SAVE_EXPR containing the increment.  All
06489      other pending sizes would be handled by gimplify_parameters.  */
06490   {
06491     tree t;
06492     for (t = nreverse (get_pending_sizes ()); t ; t = TREE_CHAIN (t))
06493       add_stmt (TREE_VALUE (t));
06494   }
06495 
06496   /* Even though we're inside a function body, we still don't want to
06497      call expand_expr to calculate the size of a variable-sized array.
06498      We haven't necessarily assigned RTL to all variables yet, so it's
06499      not safe to try to expand expressions involving them.  */
06500   cfun->x_dont_save_pending_sizes_p = 1;
06501 }
06502 
06503 /* Handle attribute((warn_unused_result)) on FNDECL and all its nested
06504    functions.  */
06505 
06506 static void
06507 c_warn_unused_result_recursively (tree fndecl)
06508 {
06509   struct cgraph_node *cgn;
06510 
06511   /* Handle attribute((warn_unused_result)).  Relies on gimple input.  */
06512   c_warn_unused_result (&DECL_SAVED_TREE (fndecl));
06513 
06514   /* Finalize all nested functions now.  */
06515   cgn = cgraph_node (fndecl);
06516   for (cgn = cgn->nested; cgn ; cgn = cgn->next_nested)
06517     c_warn_unused_result_recursively (cgn->decl);
06518 }
06519 
06520 /* Finish up a function declaration and compile that function
06521    all the way to assembler language output.  The free the storage
06522    for the function definition.
06523 
06524    This is called after parsing the body of the function definition.  */
06525 
06526 void
06527 finish_function (void)
06528 {
06529   tree fndecl = current_function_decl;
06530 
06531   label_context_stack_se = label_context_stack_se->next;
06532   label_context_stack_vm = label_context_stack_vm->next;
06533 
06534   if (TREE_CODE (fndecl) == FUNCTION_DECL
06535       && targetm.calls.promote_prototypes (TREE_TYPE (fndecl)))
06536     {
06537       tree args = DECL_ARGUMENTS (fndecl);
06538       for (; args; args = TREE_CHAIN (args))
06539   {
06540     tree type = TREE_TYPE (args);
06541     if (INTEGRAL_TYPE_P (type)
06542         && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
06543       DECL_ARG_TYPE (args) = integer_type_node;
06544   }
06545     }
06546 
06547   if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node)
06548     BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
06549 
06550   /* Must mark the RESULT_DECL as being in this function.  */
06551 
06552   if (DECL_RESULT (fndecl) && DECL_RESULT (fndecl) != error_mark_node)
06553     DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
06554 
06555   if (MAIN_NAME_P (DECL_NAME (fndecl)) && flag_hosted)
06556     {
06557       if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))
06558     != integer_type_node)
06559   {
06560     /* If warn_main is 1 (-Wmain) or 2 (-Wall), we have already warned.
06561        If warn_main is -1 (-Wno-main) we don't want to be warned.  */
06562     if (!warn_main)
06563       pedwarn ("%Jreturn type of %qD is not %<int%>", fndecl, fndecl);
06564   }
06565       else
06566   {
06567     if (flag_isoc99)
06568       {
06569         tree stmt = c_finish_return (integer_zero_node);
06570         /* Hack.  We don't want the middle-end to warn that this
06571      return is unreachable, so put the statement on the
06572      special line 0.  */
06573         annotate_with_file_line (stmt, input_filename, 0);
06574       }
06575   }
06576     }
06577 
06578   /* Tie off the statement tree for this function.  */
06579   DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
06580 
06581   finish_fname_decls ();
06582 
06583   /* Complain if there's just no return statement.  */
06584   if (warn_return_type
06585       && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl))) != VOID_TYPE
06586       && !current_function_returns_value && !current_function_returns_null
06587       /* Don't complain if we abort.  */
06588       && !current_function_returns_abnormally
06589       /* Don't warn for main().  */
06590       && !MAIN_NAME_P (DECL_NAME (fndecl))
06591       /* Or if they didn't actually specify a return type.  */
06592       && !C_FUNCTION_IMPLICIT_INT (fndecl)
06593       /* Normally, with -Wreturn-type, flow will complain.  Unless we're an
06594    inline function, as we might never be compiled separately.  */
06595       && DECL_INLINE (fndecl))
06596     warning ("no return statement in function returning non-void");
06597 
06598   /* With just -Wextra, complain only if function returns both with
06599      and without a value.  */
06600   if (extra_warnings
06601       && current_function_returns_value
06602       && current_function_returns_null)
06603     warning ("this function may return with or without a value");
06604 
06605   /* Store the end of the function, so that we get good line number
06606      info for the epilogue.  */
06607   cfun->function_end_locus = input_location;
06608 
06609   /* If we don't have ctors/dtors sections, and this is a static
06610      constructor or destructor, it must be recorded now.  */
06611   if (DECL_STATIC_CONSTRUCTOR (fndecl)
06612       && !targetm.have_ctors_dtors)
06613     static_ctors = tree_cons (NULL_TREE, fndecl, static_ctors);
06614   if (DECL_STATIC_DESTRUCTOR (fndecl)
06615       && !targetm.have_ctors_dtors)
06616     static_dtors = tree_cons (NULL_TREE, fndecl, static_dtors);
06617 
06618   /* Finalize the ELF visibility for the function.  */
06619   c_determine_visibility (fndecl);
06620 
06621   /* Genericize before inlining.  Delay genericizing nested functions
06622      until their parent function is genericized.  Since finalizing
06623      requires GENERIC, delay that as well.  */
06624 
06625   if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node
06626       && !undef_nested_function)
06627     {
06628       if (!decl_function_context (fndecl))
06629         {
06630 #ifdef KEY
06631     // Translate to spin before calling c_genericize, which lowers the
06632     // tree and destroys high-level program info useful for program
06633     // optimization.
06634           if (flag_spin_file)
06635             gspin (fndecl);
06636 #endif
06637           c_genericize (fndecl);
06638           c_warn_unused_result_recursively (fndecl);
06639 
06640     /* ??? Objc emits functions after finalizing the compilation unit.
06641        This should be cleaned up later and this conditional removed.  */
06642     if (cgraph_global_info_ready)
06643       {
06644         c_expand_body (fndecl);
06645         return;
06646       }
06647 
06648     cgraph_finalize_function (fndecl, false);
06649         }
06650       else
06651         {
06652 #ifdef KEY /* bug 11761 */
06653           error ("Nested functions not supported");
06654 #endif
06655           /* Register this function with cgraph just far enough to get it
06656             added to our parent's nested function list.  Handy, since the
06657             C front end doesn't have such a list.  */
06658           (void) cgraph_node (fndecl);
06659         }
06660     }
06661 
06662   if (!decl_function_context (fndecl))
06663     undef_nested_function = false;
06664 
06665   /* We're leaving the context of this function, so zap cfun.
06666      It's still in DECL_STRUCT_FUNCTION, and we'll restore it in
06667      tree_rest_of_compilation.  */
06668   cfun = NULL;
06669   current_function_decl = NULL;
06670 }
06671 
06672 /* Generate the RTL for the body of FNDECL.  */
06673 
06674 void
06675 c_expand_body (tree fndecl)
06676 {
06677 
06678   if (!DECL_INITIAL (fndecl)
06679       || DECL_INITIAL (fndecl) == error_mark_node)
06680     return;
06681 
06682   tree_rest_of_compilation (fndecl);
06683 
06684   if (DECL_STATIC_CONSTRUCTOR (fndecl)
06685       && targetm.have_ctors_dtors)
06686     targetm.asm_out.constructor (XEXP (DECL_RTL (fndecl), 0),
06687                                  DEFAULT_INIT_PRIORITY);
06688   if (DECL_STATIC_DESTRUCTOR (fndecl)
06689       && targetm.have_ctors_dtors)
06690     targetm.asm_out.destructor (XEXP (DECL_RTL (fndecl), 0),
06691                                 DEFAULT_INIT_PRIORITY);
06692 }
06693 
06694 /* Check the declarations given in a for-loop for satisfying the C99
06695    constraints.  */
06696 void
06697 check_for_loop_decls (void)
06698 {
06699   struct c_binding *b;
06700 
06701   if (!flag_isoc99)
06702     {
06703       /* If we get here, declarations have been used in a for loop without
06704    the C99 for loop scope.  This doesn't make much sense, so don't
06705    allow it.  */
06706       error ("%<for%> loop initial declaration used outside C99 mode");
06707       return;
06708     }
06709   /* C99 subclause 6.8.5 paragraph 3:
06710 
06711        [#3]  The  declaration  part  of  a for statement shall only
06712        declare identifiers for objects having storage class auto or
06713        register.
06714 
06715      It isn't clear whether, in this sentence, "identifiers" binds to
06716      "shall only declare" or to "objects" - that is, whether all identifiers
06717      declared must be identifiers for objects, or whether the restriction
06718      only applies to those that are.  (A question on this in comp.std.c
06719      in November 2000 received no answer.)  We implement the strictest
06720      interpretation, to avoid creating an extension which later causes
06721      problems.  */
06722 
06723   for (b = current_scope->bindings; b; b = b->prev)
06724     {
06725       tree id = b->id;
06726       tree decl = b->decl;
06727 
06728       if (!id)
06729   continue;
06730 
06731       switch (TREE_CODE (decl))
06732   {
06733   case VAR_DECL:
06734     if (TREE_STATIC (decl))
06735       error ("%Jdeclaration of static variable %qD in %<for%> loop "
06736        "initial declaration", decl, decl);
06737     else if (DECL_EXTERNAL (decl))
06738       error ("%Jdeclaration of %<extern%> variable %qD in %<for%> loop "
06739        "initial declaration", decl, decl);
06740     break;
06741 
06742   case RECORD_TYPE:
06743     error ("%<struct %E%> declared in %<for%> loop initial declaration",
06744      id);
06745     break;
06746   case UNION_TYPE:
06747     error ("%<union %E%> declared in %<for%> loop initial declaration",
06748      id);
06749     break;
06750   case ENUMERAL_TYPE:
06751     error ("%<enum %E%> declared in %<for%> loop initial declaration",
06752      id);
06753     break;
06754   default:
06755     error ("%Jdeclaration of non-variable %qD in %<for%> loop "
06756      "initial declaration", decl, decl);
06757   }
06758     }
06759 }
06760 
06761 /* Save and reinitialize the variables
06762    used during compilation of a C function.  */
06763 
06764 void
06765 c_push_function_context (struct function *f)
06766 {
06767   struct language_function *p;
06768   p = GGC_NEW (struct language_function);
06769   f->language = p;
06770 
06771   p->base.x_stmt_tree = c_stmt_tree;
06772   p->x_break_label = c_break_label;
06773   p->x_cont_label = c_cont_label;
06774   p->x_switch_stack = c_switch_stack;
06775   p->arg_info = current_function_arg_info;
06776   p->returns_value = current_function_returns_value;
06777   p->returns_null = current_function_returns_null;
06778   p->returns_abnormally = current_function_returns_abnormally;
06779   p->warn_about_return_type = warn_about_return_type;
06780   p->extern_inline = current_extern_inline;
06781 }
06782 
06783 /* Restore the variables used during compilation of a C function.  */
06784 
06785 void
06786 c_pop_function_context (struct function *f)
06787 {
06788   struct language_function *p = f->language;
06789 
06790   if (DECL_STRUCT_FUNCTION (current_function_decl) == 0
06791       && DECL_SAVED_TREE (current_function_decl) == NULL_TREE)
06792     {
06793       /* Stop pointing to the local nodes about to be freed.  */
06794       /* But DECL_INITIAL must remain nonzero so we know this
06795    was an actual function definition.  */
06796       DECL_INITIAL (current_function_decl) = error_mark_node;
06797       DECL_ARGUMENTS (current_function_decl) = 0;
06798     }
06799 
06800   c_stmt_tree = p->base.x_stmt_tree;
06801   c_break_label = p->x_break_label;
06802   c_cont_label = p->x_cont_label;
06803   c_switch_stack = p->x_switch_stack;
06804   current_function_arg_info = p->arg_info;
06805   current_function_returns_value = p->returns_value;
06806   current_function_returns_null = p->returns_null;
06807   current_function_returns_abnormally = p->returns_abnormally;
06808   warn_about_return_type = p->warn_about_return_type;
06809   current_extern_inline = p->extern_inline;
06810 
06811   f->language = NULL;
06812 }
06813 
06814 /* Copy the DECL_LANG_SPECIFIC data associated with DECL.  */
06815 
06816 void
06817 c_dup_lang_specific_decl (tree decl)
06818 {
06819   struct lang_decl *ld;
06820 
06821   if (!DECL_LANG_SPECIFIC (decl))
06822     return;
06823 
06824   ld = GGC_NEW (struct lang_decl);
06825   memcpy (ld, DECL_LANG_SPECIFIC (decl), sizeof (struct lang_decl));
06826   DECL_LANG_SPECIFIC (decl) = ld;
06827 }
06828 
06829 /* The functions below are required for functionality of doing
06830    function at once processing in the C front end. Currently these
06831    functions are not called from anywhere in the C front end, but as
06832    these changes continue, that will change.  */
06833 
06834 /* Returns nonzero if the current statement is a full expression,
06835    i.e. temporaries created during that statement should be destroyed
06836    at the end of the statement.  */
06837 
06838 int
06839 stmts_are_full_exprs_p (void)
06840 {
06841   return 0;
06842 }
06843 
06844 /* Returns the stmt_tree (if any) to which statements are currently
06845    being added.  If there is no active statement-tree, NULL is
06846    returned.  */
06847 
06848 stmt_tree
06849 current_stmt_tree (void)
06850 {
06851   return &c_stmt_tree;
06852 }
06853 
06854 /* Nonzero if TYPE is an anonymous union or struct type.  Always 0 in
06855    C.  */
06856 
06857 int
06858 anon_aggr_type_p (tree ARG_UNUSED (node))
06859 {
06860   return 0;
06861 }
06862 
06863 /* Return the global value of T as a symbol.  */
06864 
06865 tree
06866 identifier_global_value (tree t)
06867 {
06868   struct c_binding *b;
06869 
06870   for (b = I_SYMBOL_BINDING (t); b; b = b->shadowed)
06871     if (B_IN_FILE_SCOPE (b) || B_IN_EXTERNAL_SCOPE (b))
06872       return b->decl;
06873 
06874   return 0;
06875 }
06876 
06877 /* Record a builtin type for C.  If NAME is non-NULL, it is the name used;
06878    otherwise the name is found in ridpointers from RID_INDEX.  */
06879 
06880 void
06881 record_builtin_type (enum rid rid_index, const char *name, tree type)
06882 {
06883   tree id, decl;
06884   if (name == 0)
06885     id = ridpointers[(int) rid_index];
06886   else
06887     id = get_identifier (name);
06888   decl = build_decl (TYPE_DECL, id, type);
06889   pushdecl (decl);
06890   if (debug_hooks->type_decl)
06891     debug_hooks->type_decl (decl, false);
06892 }
06893 
06894 /* Build the void_list_node (void_type_node having been created).  */
06895 tree
06896 build_void_list_node (void)
06897 {
06898   tree t = build_tree_list (NULL_TREE, void_type_node);
06899   return t;
06900 }
06901 
06902 /* Return a c_parm structure with the given SPECS, ATTRS and DECLARATOR.  */
06903 
06904 struct c_parm *
06905 build_c_parm (struct c_declspecs *specs, tree attrs,
06906         struct c_declarator *declarator)
06907 {
06908   struct c_parm *ret = XOBNEW (&parser_obstack, struct c_parm);
06909   ret->specs = specs;
06910   ret->attrs = attrs;
06911   ret->declarator = declarator;
06912   return ret;
06913 }
06914 
06915 /* Return a declarator with nested attributes.  TARGET is the inner
06916    declarator to which these attributes apply.  ATTRS are the
06917    attributes.  */
06918 
06919 struct c_declarator *
06920 build_attrs_declarator (tree attrs, struct c_declarator *target)
06921 {
06922   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
06923   ret->kind = cdk_attrs;
06924   ret->declarator = target;
06925   ret->u.attrs = attrs;
06926   return ret;
06927 }
06928 
06929 /* Return a declarator for a function with arguments specified by ARGS
06930    and return type specified by TARGET.  */
06931 
06932 struct c_declarator *
06933 build_function_declarator (struct c_arg_info *args,
06934          struct c_declarator *target)
06935 {
06936   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
06937   ret->kind = cdk_function;
06938   ret->declarator = target;
06939   ret->u.arg_info = args;
06940   return ret;
06941 }
06942 
06943 /* Return a declarator for the identifier IDENT (which may be
06944    NULL_TREE for an abstract declarator).  */
06945 
06946 struct c_declarator *
06947 build_id_declarator (tree ident)
06948 {
06949   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
06950   ret->kind = cdk_id;
06951   ret->declarator = 0;
06952   ret->u.id = ident;
06953   return ret;
06954 }
06955 
06956 /* Return something to represent absolute declarators containing a *.
06957    TARGET is the absolute declarator that the * contains.
06958    TYPE_QUALS_ATTRS is a structure for type qualifiers and attributes
06959    to apply to the pointer type.  */
06960 
06961 struct c_declarator *
06962 make_pointer_declarator (struct c_declspecs *type_quals_attrs,
06963        struct c_declarator *target)
06964 {
06965   tree attrs;
06966   int quals = 0;
06967   struct c_declarator *itarget = target;
06968   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
06969   if (type_quals_attrs)
06970     {
06971       attrs = type_quals_attrs->attrs;
06972       quals = quals_from_declspecs (type_quals_attrs);
06973       if (attrs != NULL_TREE)
06974   itarget = build_attrs_declarator (attrs, target);
06975     }
06976   ret->kind = cdk_pointer;
06977   ret->declarator = itarget;
06978   ret->u.pointer_quals = quals;
06979   return ret;
06980 }
06981 
06982 /* Return a pointer to a structure for an empty list of declaration
06983    specifiers.  */
06984 
06985 struct c_declspecs *
06986 build_null_declspecs (void)
06987 {
06988   struct c_declspecs *ret = XOBNEW (&parser_obstack, struct c_declspecs);
06989   ret->type = 0;
06990   ret->decl_attr = 0;
06991   ret->attrs = 0;
06992   ret->typespec_word = cts_none;
06993   ret->storage_class = csc_none;
06994   ret->non_sc_seen_p = false;
06995   ret->typedef_p = false;
06996   ret->tag_defined_p = false;
06997   ret->explicit_signed_p = false;
06998   ret->deprecated_p = false;
06999   ret->default_int_p = false;
07000   ret->long_p = false;
07001   ret->long_long_p = false;
07002   ret->short_p = false;
07003   ret->signed_p = false;
07004   ret->unsigned_p = false;
07005   ret->complex_p = false;
07006   ret->inline_p = false;
07007   ret->thread_p = false;
07008   ret->const_p = false;
07009   ret->volatile_p = false;
07010   ret->restrict_p = false;
07011   return ret;
07012 }
07013 
07014 /* Add the type qualifier QUAL to the declaration specifiers SPECS,
07015    returning SPECS.  */
07016 
07017 struct c_declspecs *
07018 declspecs_add_qual (struct c_declspecs *specs, tree qual)
07019 {
07020   enum rid i;
07021   bool dupe = false;
07022   specs->non_sc_seen_p = true;
07023   gcc_assert (TREE_CODE (qual) == IDENTIFIER_NODE
07024         && C_IS_RESERVED_WORD (qual));
07025   i = C_RID_CODE (qual);
07026   switch (i)
07027     {
07028     case RID_CONST:
07029       dupe = specs->const_p;
07030       specs->const_p = true;
07031       break;
07032     case RID_VOLATILE:
07033       dupe = specs->volatile_p;
07034       specs->volatile_p = true;
07035       break;
07036     case RID_RESTRICT:
07037       dupe = specs->restrict_p;
07038       specs->restrict_p = true;
07039       break;
07040     default:
07041       gcc_unreachable ();
07042     }
07043   if (dupe && pedantic && !flag_isoc99)
07044     pedwarn ("duplicate %qs", IDENTIFIER_POINTER (qual));
07045   return specs;
07046 }
07047 
07048 /* Add the type specifier TYPE to the declaration specifiers SPECS,
07049    returning SPECS.  */
07050 
07051 struct c_declspecs *
07052 declspecs_add_type (struct c_declspecs *specs, struct c_typespec spec)
07053 {
07054   tree type = spec.spec;
07055   specs->non_sc_seen_p = true;
07056   if (TREE_DEPRECATED (type))
07057     specs->deprecated_p = true;
07058 
07059   /* Handle type specifier keywords.  */
07060   if (TREE_CODE (type) == IDENTIFIER_NODE && C_IS_RESERVED_WORD (type))
07061     {
07062       enum rid i = C_RID_CODE (type);
07063       if (specs->type)
07064   {
07065     error ("two or more data types in declaration specifiers");
07066     return specs;
07067   }
07068       if ((int) i <= (int) RID_LAST_MODIFIER)
07069   {
07070     /* "long", "short", "signed", "unsigned" or "_Complex".  */
07071     bool dupe = false;
07072     switch (i)
07073       {
07074       case RID_LONG:
07075         if (specs->long_long_p)
07076     {
07077       error ("%<long long long%> is too long for GCC");
07078       break;
07079     }
07080         if (specs->long_p)
07081     {
07082       if (specs->typespec_word == cts_double)
07083         {
07084           error ("both %<long long%> and %<double%> in "
07085            "declaration specifiers");
07086           break;
07087         }
07088       if (pedantic && !flag_isoc99 && !in_system_header
07089           && warn_long_long)
07090         pedwarn ("ISO C90 does not support %<long long%>");
07091       specs->long_long_p = 1;
07092       break;
07093     }
07094         if (specs->short_p)
07095     error ("both %<long%> and %<short%> in "
07096            "declaration specifiers");
07097         else if (specs->typespec_word == cts_void)
07098     error ("both %<long%> and %<void%> in "
07099            "declaration specifiers");
07100         else if (specs->typespec_word == cts_bool)
07101     error ("both %<long%> and %<_Bool%> in "
07102            "declaration specifiers");
07103         else if (specs->typespec_word == cts_char)
07104     error ("both %<long%> and %<char%> in "
07105            "declaration specifiers");
07106         else if (specs->typespec_word == cts_float)
07107     error ("both %<long%> and %<float%> in "
07108            "declaration specifiers");
07109         else
07110     specs->long_p = true;
07111         break;
07112       case RID_SHORT:
07113         dupe = specs->short_p;
07114         if (specs->long_p)
07115     error ("both %<long%> and %<short%> in "
07116            "declaration specifiers");
07117         else if (specs->typespec_word == cts_void)
07118     error ("both %<short%> and %<void%> in "
07119            "declaration specifiers");
07120         else if (specs->typespec_word == cts_bool)
07121     error ("both %<short%> and %<_Bool%> in "
07122            "declaration specifiers");
07123         else if (specs->typespec_word == cts_char)
07124     error ("both %<short%> and %<char%> in "
07125            "declaration specifiers");
07126         else if (specs->typespec_word == cts_float)
07127     error ("both %<short%> and %<float%> in "
07128            "declaration specifiers");
07129         else if (specs->typespec_word == cts_double)
07130     error ("both %<short%> and %<double%> in "
07131            "declaration specifiers");
07132         else
07133     specs->short_p = true;
07134         break;
07135       case RID_SIGNED:
07136         dupe = specs->signed_p;
07137         if (specs->unsigned_p)
07138     error ("both %<signed%> and %<unsigned%> in "
07139            "declaration specifiers");
07140         else if (specs->typespec_word == cts_void)
07141     error ("both %<signed%> and %<void%> in "
07142            "declaration specifiers");
07143         else if (specs->typespec_word == cts_bool)
07144     error ("both %<signed%> and %<_Bool%> in "
07145            "declaration specifiers");
07146         else if (specs->typespec_word == cts_float)
07147     error ("both %<signed%> and %<float%> in "
07148            "declaration specifiers");
07149         else if (specs->typespec_word == cts_double)
07150     error ("both %<signed%> and %<double%> in "
07151            "declaration specifiers");
07152         else
07153     specs->signed_p = true;
07154         break;
07155       case RID_UNSIGNED:
07156         dupe = specs->unsigned_p;
07157         if (specs->signed_p)
07158     error ("both %<signed%> and %<unsigned%> in "
07159            "declaration specifiers");
07160         else if (specs->typespec_word == cts_void)
07161     error ("both %<unsigned%> and %<void%> in "
07162            "declaration specifiers");
07163         else if (specs->typespec_word == cts_bool)
07164     error ("both %<unsigned%> and %<_Bool%> in "
07165            "declaration specifiers");
07166         else if (specs->typespec_word == cts_float)
07167     error ("both %<unsigned%> and %<float%> in "
07168            "declaration specifiers");
07169         else if (specs->typespec_word == cts_double)
07170     error ("both %<unsigned%> and %<double%> in "
07171            "declaration specifiers");
07172         else
07173     specs->unsigned_p = true;
07174         break;
07175       case RID_COMPLEX:
07176         dupe = specs->complex_p;
07177         if (pedantic && !flag_isoc99 && !in_system_header)
07178     pedwarn ("ISO C90 does not support complex types");
07179         if (specs->typespec_word == cts_void)
07180     error ("both %<complex%> and %<void%> in "
07181            "declaration specifiers");
07182         else if (specs->typespec_word == cts_bool)
07183     error ("both %<complex%> and %<_Bool%> in "
07184            "declaration specifiers");
07185         else
07186     specs->complex_p = true;
07187         break;
07188       default:
07189         gcc_unreachable ();
07190       }
07191 
07192     if (dupe)
07193       error ("duplicate %qs", IDENTIFIER_POINTER (type));
07194 
07195     return specs;
07196   }
07197       else
07198   {
07199     /* "void", "_Bool", "char", "int", "float" or "double".  */
07200     if (specs->typespec_word != cts_none)
07201       {
07202         error ("two or more data types in declaration specifiers");
07203         return specs;
07204       }
07205     switch (i)
07206       {
07207       case RID_VOID:
07208         if (specs->long_p)
07209     error ("both %<long%> and %<void%> in "
07210            "declaration specifiers");
07211         else if (specs->short_p)
07212     error ("both %<short%> and %<void%> in "
07213            "declaration specifiers");
07214         else if (specs->signed_p)
07215     error ("both %<signed%> and %<void%> in "
07216            "declaration specifiers");
07217         else if (specs->unsigned_p)
07218     error ("both %<unsigned%> and %<void%> in "
07219            "declaration specifiers");
07220         else if (specs->complex_p)
07221     error ("both %<complex%> and %<void%> in "
07222            "declaration specifiers");
07223         else
07224     specs->typespec_word = cts_void;
07225         return specs;
07226       case RID_BOOL:
07227         if (specs->long_p)
07228     error ("both %<long%> and %<_Bool%> in "
07229            "declaration specifiers");
07230         else if (specs->short_p)
07231     error ("both %<short%> and %<_Bool%> in "
07232            "declaration specifiers");
07233         else if (specs->signed_p)
07234     error ("both %<signed%> and %<_Bool%> in "
07235            "declaration specifiers");
07236         else if (specs->unsigned_p)
07237     error ("both %<unsigned%> and %<_Bool%> in "
07238            "declaration specifiers");
07239         else if (specs->complex_p)
07240     error ("both %<complex%> and %<_Bool%> in "
07241            "declaration specifiers");
07242         else
07243     specs->typespec_word = cts_bool;
07244         return specs;
07245       case RID_CHAR:
07246         if (specs->long_p)
07247     error ("both %<long%> and %<char%> in "
07248            "declaration specifiers");
07249         else if (specs->short_p)
07250     error ("both %<short%> and %<char%> in "
07251            "declaration specifiers");
07252         else
07253     specs->typespec_word = cts_char;
07254         return specs;
07255       case RID_INT:
07256         specs->typespec_word = cts_int;
07257         return specs;
07258       case RID_FLOAT:
07259         if (specs->long_p)
07260     error ("both %<long%> and %<float%> in "
07261            "declaration specifiers");
07262         else if (specs->short_p)
07263     error ("both %<short%> and %<float%> in "
07264            "declaration specifiers");
07265         else if (specs->signed_p)
07266     error ("both %<signed%> and %<float%> in "
07267            "declaration specifiers");
07268         else if (specs->unsigned_p)
07269     error ("both %<unsigned%> and %<float%> in "
07270            "declaration specifiers");
07271         else
07272     specs->typespec_word = cts_float;
07273         return specs;
07274       case RID_DOUBLE:
07275         if (specs->long_long_p)
07276     error ("both %<long long%> and %<double%> in "
07277            "declaration specifiers");
07278         else if (specs->short_p)
07279     error ("both %<short%> and %<double%> in "
07280            "declaration specifiers");
07281         else if (specs->signed_p)
07282     error ("both %<signed%> and %<double%> in "
07283            "declaration specifiers");
07284         else if (specs->unsigned_p)
07285     error ("both %<unsigned%> and %<double%> in "
07286            "declaration specifiers");
07287         else
07288     specs->typespec_word = cts_double;
07289         return specs;
07290       default:
07291         /* ObjC reserved word "id", handled below.  */
07292         break;
07293       }
07294   }
07295     }
07296 
07297   /* Now we have a typedef (a TYPE_DECL node), an identifier (some
07298      form of ObjC type, cases such as "int" and "long" being handled
07299      above), a TYPE (struct, union, enum and typeof specifiers) or an
07300      ERROR_MARK.  In none of these cases may there have previously
07301      been any type specifiers.  */
07302   if (specs->type || specs->typespec_word != cts_none
07303       || specs->long_p || specs->short_p || specs->signed_p
07304       || specs->unsigned_p || specs->complex_p)
07305     error ("two or more data types in declaration specifiers");
07306   else if (TREE_CODE (type) == TYPE_DECL)
07307     {
07308       if (TREE_TYPE (type) == error_mark_node)
07309   ; /* Allow the type to default to int to avoid cascading errors.  */
07310       else
07311   {
07312     specs->type = TREE_TYPE (type);
07313     specs->decl_attr = DECL_ATTRIBUTES (type);
07314     specs->typedef_p = true;
07315     specs->explicit_signed_p = C_TYPEDEF_EXPLICITLY_SIGNED (type);
07316   }
07317     }
07318   else if (TREE_CODE (type) == IDENTIFIER_NODE)
07319     {
07320       tree t = lookup_name (type);
07321       if (!t || TREE_CODE (t) != TYPE_DECL)
07322   error ("%qs fails to be a typedef or built in type",
07323          IDENTIFIER_POINTER (type));
07324       else if (TREE_TYPE (t) == error_mark_node)
07325   ;
07326       else
07327   specs->type = TREE_TYPE (t);
07328     }
07329   else if (TREE_CODE (type) != ERROR_MARK)
07330     {
07331       if (spec.kind == ctsk_tagdef || spec.kind == ctsk_tagfirstref)
07332   specs->tag_defined_p = true;
07333       if (spec.kind == ctsk_typeof)
07334   specs->typedef_p = true;
07335       specs->type = type;
07336     }
07337 
07338   return specs;
07339 }
07340 
07341 /* Add the storage class specifier or function specifier SCSPEC to the
07342    declaration specifiers SPECS, returning SPECS.  */
07343 
07344 struct c_declspecs *
07345 declspecs_add_scspec (struct c_declspecs *specs, tree scspec)
07346 {
07347   enum rid i;
07348   enum c_storage_class n = csc_none;
07349   bool dupe = false;
07350   gcc_assert (TREE_CODE (scspec) == IDENTIFIER_NODE
07351         && C_IS_RESERVED_WORD (scspec));
07352   i = C_RID_CODE (scspec);
07353   if (extra_warnings && specs->non_sc_seen_p)
07354     warning ("%qs is not at beginning of declaration",
07355        IDENTIFIER_POINTER (scspec));
07356   switch (i)
07357     {
07358     case RID_INLINE:
07359       /* C99 permits duplicate inline.  Although of doubtful utility,
07360    it seems simplest to permit it in gnu89 mode as well, as
07361    there is also little utility in maintaining this as a
07362    difference between gnu89 and C99 inline.  */
07363       dupe = false;
07364       specs->inline_p = true;
07365       break;
07366     case RID_THREAD:
07367       dupe = specs->thread_p;
07368       if (specs->storage_class == csc_auto)
07369   error ("%<__thread%> used with %<auto%>");
07370       else if (specs->storage_class == csc_register)
07371   error ("%<__thread%> used with %<register%>");
07372       else if (specs->storage_class == csc_typedef)
07373   error ("%<__thread%> used with %<typedef%>");
07374       else
07375   specs->thread_p = true;
07376       break;
07377     case RID_AUTO:
07378       n = csc_auto;
07379       break;
07380     case RID_EXTERN:
07381       n = csc_extern;
07382       /* Diagnose "__thread extern".  */
07383       if (specs->thread_p)
07384   error ("%<__thread%> before %<extern%>");
07385       break;
07386     case RID_REGISTER:
07387       n = csc_register;
07388       break;
07389     case RID_STATIC:
07390       n = csc_static;
07391       /* Diagnose "__thread static".  */
07392       if (specs->thread_p)
07393   error ("%<__thread%> before %<static%>");
07394       break;
07395     case RID_TYPEDEF:
07396       n = csc_typedef;
07397       break;
07398     default:
07399       gcc_unreachable ();
07400     }
07401   if (n != csc_none && n == specs->storage_class)
07402     dupe = true;
07403   if (dupe)
07404     error ("duplicate %qs", IDENTIFIER_POINTER (scspec));
07405   if (n != csc_none)
07406     {
07407       if (specs->storage_class != csc_none && n != specs->storage_class)
07408   {
07409     error ("multiple storage classes in declaration specifiers");
07410   }
07411       else
07412   {
07413     specs->storage_class = n;
07414     if (n != csc_extern && n != csc_static && specs->thread_p)
07415       {
07416         error ("%<__thread%> used with %qs",
07417          IDENTIFIER_POINTER (scspec));
07418         specs->thread_p = false;
07419       }
07420   }
07421     }
07422   return specs;
07423 }
07424 
07425 /* Add the attributes ATTRS to the declaration specifiers SPECS,
07426    returning SPECS.  */
07427 
07428 struct c_declspecs *
07429 declspecs_add_attrs (struct c_declspecs *specs, tree attrs)
07430 {
07431   specs->attrs = chainon (attrs, specs->attrs);
07432   return specs;
07433 }
07434 
07435 /* Combine "long", "short", "signed", "unsigned" and "_Complex" type
07436    specifiers with any other type specifier to determine the resulting
07437    type.  This is where ISO C checks on complex types are made, since
07438    "_Complex long" is a prefix of the valid ISO C type "_Complex long
07439    double".  */
07440 
07441 struct c_declspecs *
07442 finish_declspecs (struct c_declspecs *specs)
07443 {
07444   /* If a type was specified as a whole, we have no modifiers and are
07445      done.  */
07446   if (specs->type != NULL_TREE)
07447     {
07448       gcc_assert (!specs->long_p && !specs->long_long_p && !specs->short_p
07449       && !specs->signed_p && !specs->unsigned_p
07450       && !specs->complex_p);
07451       return specs;
07452     }
07453 
07454   /* If none of "void", "_Bool", "char", "int", "float" or "double"
07455      has been specified, treat it as "int" unless "_Complex" is
07456      present and there are no other specifiers.  If we just have
07457      "_Complex", it is equivalent to "_Complex double", but e.g.
07458      "_Complex short" is equivalent to "_Complex short int".  */
07459   if (specs->typespec_word == cts_none)
07460     {
07461       if (specs->long_p || specs->short_p
07462     || specs->signed_p || specs->unsigned_p)
07463   {
07464     specs->typespec_word = cts_int;
07465   }
07466       else if (specs->complex_p)
07467   {
07468     specs->typespec_word = cts_double;
07469     if (pedantic)
07470       pedwarn ("ISO C does not support plain %<complex%> meaning "
07471          "%<double complex%>");
07472   }
07473       else
07474   {
07475     specs->typespec_word = cts_int;
07476     specs->default_int_p = true;
07477     /* We don't diagnose this here because grokdeclarator will
07478        give more specific diagnostics according to whether it is
07479        a function definition.  */
07480   }
07481     }
07482 
07483   /* If "signed" was specified, record this to distinguish "int" and
07484      "signed int" in the case of a bit-field with
07485      -funsigned-bitfields.  */
07486   specs->explicit_signed_p = specs->signed_p;
07487 
07488   /* Now compute the actual type.  */
07489   switch (specs->typespec_word)
07490     {
07491     case cts_void:
07492       gcc_assert (!specs->long_p && !specs->short_p
07493       && !specs->signed_p && !specs->unsigned_p
07494       && !specs->complex_p);
07495       specs->type = void_type_node;
07496       break;
07497     case cts_bool:
07498       gcc_assert (!specs->long_p && !specs->short_p
07499       && !specs->signed_p && !specs->unsigned_p
07500       && !specs->complex_p);
07501       specs->type = boolean_type_node;
07502       break;
07503     case cts_char:
07504       gcc_assert (!specs->long_p && !specs->short_p);
07505       gcc_assert (!(specs->signed_p && specs->unsigned_p));
07506       if (specs->signed_p)
07507   specs->type = signed_char_type_node;
07508       else if (specs->unsigned_p)
07509   specs->type = unsigned_char_type_node;
07510       else
07511   specs->type = char_type_node;
07512       if (specs->complex_p)
07513   {
07514     if (pedantic)
07515       pedwarn ("ISO C does not support complex integer types");
07516     specs->type = build_complex_type (specs->type);
07517   }
07518       break;
07519     case cts_int:
07520       gcc_assert (!(specs->long_p && specs->short_p));
07521       gcc_assert (!(specs->signed_p && specs->unsigned_p));
07522       if (specs->long_long_p)
07523       {
07524 #ifdef TARG_SL
07525     if (Long_Long_Support == TRUE)
07526     {
07527       specs->type = (specs->unsigned_p
07528            ? long_long_unsigned_type_node
07529            : long_long_integer_type_node);
07530     }
07531     else
07532     {
07533       warning("\"long long\" is mapped to \"long\", "
07534               "Please use \"-mlong-long\" option to enbale long long type suporting");
07535           specs->type = (specs->unsigned_p
07536                          ? long_unsigned_type_node
07537                          : long_integer_type_node);
07538     }
07539 #else
07540     specs->type = (specs->unsigned_p
07541            ? long_long_unsigned_type_node
07542            : long_long_integer_type_node);
07543     
07544 #endif
07545       }
07546       else if (specs->long_p)
07547   specs->type = (specs->unsigned_p
07548            ? long_unsigned_type_node
07549            : long_integer_type_node);
07550       else if (specs->short_p)
07551   specs->type = (specs->unsigned_p
07552            ? short_unsigned_type_node
07553            : short_integer_type_node);
07554       else
07555   specs->type = (specs->unsigned_p
07556            ? unsigned_type_node
07557            : integer_type_node);
07558       if (specs->complex_p)
07559   {
07560 #ifdef TARG_SL
07561       error("Unsupported type: \"complex\"");
07562 #endif
07563     if (pedantic)
07564       pedwarn ("ISO C does not support complex integer types");
07565     specs->type = build_complex_type (specs->type);
07566   }
07567       break;
07568     case cts_float:
07569       gcc_assert (!specs->long_p && !specs->short_p
07570       && !specs->signed_p && !specs->unsigned_p);
07571       specs->type = (specs->complex_p
07572          ? complex_float_type_node
07573          : float_type_node);
07574          
07575 #ifdef TARG_SL
07576       if (TYPE_MAIN_VARIANT(specs->type) == float_type_node)
07577       {
07578         if (Float_Point_Support == FALSE)
07579         {    
07580           error("\"float\" type is not supported in default mode, "
07581                   "Please use \"-msoft-float\" option to enable float point emulation");
07582         }
07583       }
07584       else
07585       {
07586         warning("Unsupported type: \"complex float\"");
07587       }
07588 #endif
07589 
07590       break;
07591     case cts_double:
07592       gcc_assert (!specs->long_long_p && !specs->short_p
07593       && !specs->signed_p && !specs->unsigned_p);
07594       if (specs->long_p)
07595   {
07596     specs->type = (specs->complex_p
07597        ? complex_long_double_type_node
07598        : long_double_type_node);
07599   }
07600       else
07601   {
07602     specs->type = (specs->complex_p
07603        ? complex_double_type_node
07604        : double_type_node);
07605   }
07606   
07607 #ifdef TARG_SL 
07608     if (TYPE_MAIN_VARIANT(specs->type) == double_type_node)
07609     {
07610       if (Float_Point_Support == FALSE)
07611       {     
07612         error("\"double\" type is not supported in default mode, "
07613               "Please use \"-msoft-float\" option to enable float point emulation");
07614       }
07615     }
07616     else
07617     {
07618         warning("Unsupported type: \"complex/long double\"");
07619     }
07620 #endif
07621 
07622     break;
07623     default:
07624       gcc_unreachable ();
07625     }
07626 
07627   return specs;
07628 }
07629 
07630 /* Synthesize a function which calls all the global ctors or global
07631    dtors in this file.  This is only used for targets which do not
07632    support .ctors/.dtors sections.  FIXME: Migrate into cgraph.  */
07633 static void
07634 build_cdtor (int method_type, tree cdtors)
07635 {
07636   tree body = 0;
07637 
07638   if (!cdtors)
07639     return;
07640 
07641   for (; cdtors; cdtors = TREE_CHAIN (cdtors))
07642     append_to_statement_list (build_function_call (TREE_VALUE (cdtors), 0),
07643             &body);
07644 
07645   cgraph_build_static_cdtor (method_type, body, DEFAULT_INIT_PRIORITY);
07646 }
07647 
07648 /* A subroutine of c_write_global_declarations.  Perform final processing
07649    on one file scope's declarations (or the external scope's declarations),
07650    GLOBALS.  */
07651 
07652 #include <stdlib.h>
07653 
07654 static void
07655 c_write_global_declarations_1 (tree globals)
07656 {
07657   tree decl;
07658 
07659   /* Process the decls in the order they were written.  */
07660   for (decl = globals; decl; decl = TREE_CHAIN (decl))
07661     {
07662       /* Check for used but undefined static functions using the C
07663    standard's definition of "used", and set TREE_NO_WARNING so
07664    that check_global_declarations doesn't repeat the check.  */
07665       if (TREE_CODE (decl) == FUNCTION_DECL
07666     && DECL_INITIAL (decl) == 0
07667     && DECL_EXTERNAL (decl)
07668     && !TREE_PUBLIC (decl)
07669     && C_DECL_USED (decl))
07670   {
07671     pedwarn ("%J%qF used but never defined", decl, decl);
07672     TREE_NO_WARNING (decl) = 1;
07673   }
07674 
07675       wrapup_global_declaration_1 (decl);
07676       wrapup_global_declaration_2 (decl);
07677       check_global_declaration_1 (decl);
07678 
07679 #ifdef KEY
07680       if (!DECL_IS_BUILTIN (decl)) {
07681         if (flag_spin_file)
07682           gspin (decl);
07683       }
07684 #endif
07685     }
07686 }
07687 
07688 /* A subroutine of c_write_global_declarations Emit debug information for each
07689    of the declarations in GLOBALS.  */
07690 
07691 static void
07692 c_write_global_declarations_2 (tree globals)
07693 {
07694   tree decl;
07695 
07696   for (decl = globals; decl ; decl = TREE_CHAIN (decl))
07697     debug_hooks->global_decl (decl);
07698 }
07699 
07700 /* Preserve the external declarations scope across a garbage collect.  */
07701 static GTY(()) tree ext_block;
07702 
07703 void
07704 c_write_global_declarations (void)
07705 {
07706   tree t;
07707 #ifdef KEY
07708   extern void remove_asm_file (void);
07709 #endif
07710 
07711   /* We don't want to do this if generating a PCH.  */
07712   if (pch_file)
07713     return;
07714 
07715   /* Don't waste time on further processing if -fsyntax-only or we've
07716      encountered errors.  */
07717   if (flag_syntax_only || errorcount || sorrycount || cpp_errors (parse_in))
07718     return;
07719 
07720   /* Close the external scope.  */
07721   ext_block = pop_scope ();
07722   external_scope = 0;
07723   gcc_assert (!current_scope);
07724 
07725   /* Process all file scopes in this compilation, and the external_scope,
07726      through wrapup_global_declarations and check_global_declarations.  */
07727   for (t = all_translation_units; t; t = TREE_CHAIN (t))
07728     c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t)));
07729   c_write_global_declarations_1 (BLOCK_VARS (ext_block));
07730 
07731   /* Generate functions to call static constructors and destructors
07732      for targets that do not support .ctors/.dtors sections.  These
07733      functions have magic names which are detected by collect2.  */
07734   build_cdtor ('I', static_ctors); static_ctors = 0;
07735   build_cdtor ('D', static_dtors); static_dtors = 0;
07736 
07737 #ifdef KEY
07738   if (flag_spin_file) {
07739     remove_asm_file ();
07740     if (!errorcount)
07741       exit (EXIT_SUCCESS);
07742     else
07743       exit (2); // Corresponding to RC_USER_ERROR as the ekopath driver expects.
07744   }
07745 #endif
07746 
07747   /* We're done parsing; proceed to optimize and emit assembly.
07748      FIXME: shouldn't be the front end's responsibility to call this.  */
07749   cgraph_optimize ();
07750 
07751   /* After cgraph has had a chance to emit everything that's going to
07752      be emitted, output debug information for globals.  */
07753   if (errorcount == 0 && sorrycount == 0)
07754     {
07755       timevar_push (TV_SYMOUT);
07756       for (t = all_translation_units; t; t = TREE_CHAIN (t))
07757   c_write_global_declarations_2 (BLOCK_VARS (DECL_INITIAL (t)));
07758       c_write_global_declarations_2 (