OSDN Git Service

* Fix for g++/15861
[pf3gnuchains/gcc-fork.git] / gcc / c-decl.c
index 05bc8be..6414955 100644 (file)
@@ -49,6 +49,11 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "timevar.h"
 #include "c-common.h"
 #include "c-pragma.h"
+#include "langhooks.h"
+#include "tree-mudflap.h"
+#include "tree-gimple.h"
+#include "diagnostic.h"
+#include "tree-dump.h"
 #include "cgraph.h"
 #include "hashtab.h"
 #include "libfuncs.h"
@@ -66,11 +71,14 @@ enum decl_context
 \f
 /* Nonzero if we have seen an invalid cross reference
    to a struct, union, or enum, but not yet printed the message.  */
-
 tree pending_invalid_xref;
+
 /* File and line to appear in the eventual error message.  */
 location_t pending_invalid_xref_location;
 
+/* True means we've initialized exception handling.  */
+bool c_eh_initialized_p;
+
 /* While defining an enum type, this is 1 plus the last enumerator
    constant value.  Note that will do not have to save this or `enum_overflow'
    around nested function definition since such a definition could only
@@ -100,17 +108,15 @@ static location_t current_function_prototype_locus;
 
 static GTY(()) struct stmt_tree_s c_stmt_tree;
 
-/* The current scope statement stack.  */
-
-static GTY(()) tree c_scope_stmt_stack;
-
 /* State saving variables.  */
-int c_in_iteration_stmt;
-int c_in_case_stmt;
+tree c_break_label;
+tree c_cont_label;
 
-/* A DECL for the current file-scope context.  */
+/* Linked list of TRANSLATION_UNIT_DECLS for the translation units
+   included in this invocation.  Note that the current translation
+   unit is not included in this list.  */
 
-static GTY(()) tree current_file_decl;
+static GTY(()) tree all_translation_units;
 
 /* A list of decls to be made automatically visible in each file scope.  */
 static GTY(()) tree visible_builtins;
@@ -149,16 +155,23 @@ bool c_override_global_bindings_to_false;
    chained together by the ->prev field, which (as the name implies)
    runs in reverse order.  All the decls in a given namespace bound to
    a given identifier are chained by the ->shadowed field, which runs
-   from inner to outer scopes.  Finally, the ->contour field points
-   back to the relevant scope structure; this is mainly used to make
-   decls in the externals scope invisible (see below).
+   from inner to outer scopes.
 
    The ->decl field usually points to a DECL node, but there are two
    exceptions.  In the namespace of type tags, the bound entity is a
    RECORD_TYPE, UNION_TYPE, or ENUMERAL_TYPE node.  If an undeclared
    identifier is encountered, it is bound to error_mark_node to
    suppress further errors about that identifier in the current
-   function.  */
+   function.
+
+   The depth field is copied from the scope structure that holds this
+   decl.  It is used to preserve the proper ordering of the ->shadowed
+   field (see bind()) and also for a handful of special-case checks.
+   Finally, the invisible bit is true for a decl which should be
+   ignored for purposes of normal name lookup, and the nested bit is
+   true for a decl that's been bound a second time in an inner scope;
+   in all such cases, the binding in the outer scope will have its
+   invisible bit true.  */
 
 struct c_binding GTY((chain_next ("%h.prev")))
 {
@@ -166,8 +179,15 @@ struct c_binding GTY((chain_next ("%h.prev")))
   tree id;                     /* the identifier it's bound to */
   struct c_binding *prev;      /* the previous decl in this scope */
   struct c_binding *shadowed;  /* the innermost decl shadowed by this one */
-  struct c_scope *contour;     /* the scope in which this decl is bound */
+  unsigned int depth : 28;      /* depth of this scope */
+  BOOL_BITFIELD invisible : 1;  /* normal lookup should ignore this binding */
+  BOOL_BITFIELD nested : 1;     /* do not set DECL_CONTEXT when popping */
+  /* two free bits */
 };
+#define B_IN_SCOPE(b1, b2) ((b1)->depth == (b2)->depth)
+#define B_IN_CURRENT_SCOPE(b) ((b)->depth == current_scope->depth)
+#define B_IN_FILE_SCOPE(b) ((b)->depth == 1 /*file_scope->depth*/)
+#define B_IN_EXTERNAL_SCOPE(b) ((b)->depth == 0 /*external_scope->depth*/)
 
 #define I_SYMBOL_BINDING(node) \
   (((struct lang_identifier *)IDENTIFIER_NODE_CHECK(node))->symbol_binding)
@@ -317,11 +337,11 @@ static GTY(()) struct c_scope *external_scope;
 
 /* A chain of c_scope structures awaiting reuse.  */
 
-static GTY((deletable (""))) struct c_scope *scope_freelist;
+static GTY((deletable)) struct c_scope *scope_freelist;
 
 /* A chain of c_binding structures awaiting reuse.  */
 
-static GTY((deletable (""))) struct c_binding *binding_freelist;
+static GTY((deletable)) struct c_binding *binding_freelist;
 
 /* Append VAR to LIST in scope SCOPE.  */
 #define SCOPE_LIST_APPEND(scope, list, decl) do {      \
@@ -357,7 +377,8 @@ static bool next_is_function_body;
 
 /* Functions called automatically at the beginning and end of execution.  */
 
-tree static_ctors, static_dtors;
+static GTY(()) tree static_ctors;
+static GTY(()) tree static_dtors;
 
 /* Forward declarations.  */
 static tree lookup_name_in_scope (tree, struct c_scope *);
@@ -397,7 +418,7 @@ c_print_identifier (FILE *file, tree node, int indent)
    which may be any of several kinds of DECL or TYPE or error_mark_node,
    in the scope SCOPE.  */
 static void
-bind (tree name, tree decl, struct c_scope *scope)
+bind (tree name, tree decl, struct c_scope *scope, bool invisible, bool nested)
 {
   struct c_binding *b, **here;
 
@@ -412,7 +433,9 @@ bind (tree name, tree decl, struct c_scope *scope)
   b->shadowed = 0;
   b->decl = decl;
   b->id = name;
-  b->contour = scope;
+  b->depth = scope->depth;
+  b->invisible = invisible;
+  b->nested = nested;
 
   b->prev = scope->bindings;
   scope->bindings = b;
@@ -440,7 +463,7 @@ bind (tree name, tree decl, struct c_scope *scope)
   /* Locate the appropriate place in the chain of shadowed decls
      to insert this binding.  Normally, scope == current_scope and
      this does nothing.  */
-  while (*here && (*here)->contour->depth > scope->depth)
+  while (*here && (*here)->depth > scope->depth)
     here = &(*here)->shadowed;
 
   b->shadowed = *here;
@@ -456,10 +479,7 @@ free_binding_and_advance (struct c_binding *b)
 {
   struct c_binding *prev = b->prev;
 
-  b->id = 0;
-  b->decl = 0;
-  b->contour = 0;
-  b->shadowed = 0;
+  memset (b, 0, sizeof (struct c_binding));
   b->prev = binding_freelist;
   binding_freelist = b;
 
@@ -596,12 +616,22 @@ push_scope (void)
          scope->depth--;
          sorry ("GCC supports only %u nested scopes\n", scope->depth);
        }
-      
+
       current_scope        = scope;
       keep_next_level_flag = false;
     }
 }
 
+/* Set the TYPE_CONTEXT of all of TYPE's variants to CONTEXT.  */
+
+static void
+set_type_context (tree type, tree context)
+{
+  for (type = TYPE_MAIN_VARIANT (type); type;
+       type = TYPE_NEXT_VARIANT (type))
+    TYPE_CONTEXT (type) = context;
+}
+
 /* Exit a scope.  Restore the state of the identifier-decl mappings
    that were in effect when this scope was entered.  Return a BLOCK
    node containing all the DECLs in this scope that are of interest
@@ -649,7 +679,12 @@ pop_scope (void)
   if (scope->function_body)
     context = current_function_decl;
   else if (scope == file_scope)
-    context = current_file_decl;
+    {
+      tree file_decl = build_decl (TRANSLATION_UNIT_DECL, 0, 0);
+      TREE_CHAIN (file_decl) = all_translation_units;
+      all_translation_units = file_decl;
+      context = file_decl;
+    }
   else
     context = block;
 
@@ -676,7 +711,7 @@ pop_scope (void)
          /* Labels go in BLOCK_VARS.  */
          TREE_CHAIN (p) = BLOCK_VARS (block);
          BLOCK_VARS (block) = p;
+
 #ifdef ENABLE_CHECKING
          if (I_LABEL_BINDING (b->id) != b) abort ();
 #endif
@@ -686,7 +721,7 @@ pop_scope (void)
        case ENUMERAL_TYPE:
        case UNION_TYPE:
        case RECORD_TYPE:
-         TYPE_CONTEXT (p) = context;
+         set_type_context (p, context);
 
          /* Types may not have tag-names, in which case the type
             appears in the bindings list with b->id NULL.  */
@@ -731,11 +766,22 @@ pop_scope (void)
        common_symbol:
          /* All of these go in BLOCK_VARS, but only if this is the
             binding in the home scope.  */
-         if (!C_DECL_IN_EXTERNAL_SCOPE (p) || scope == external_scope)
+         if (!b->nested)
            {
              TREE_CHAIN (p) = BLOCK_VARS (block);
              BLOCK_VARS (block) = p;
            }
+         /* If this is the file scope, and we are processing more
+            than one translation unit in this compilation, set
+            DECL_CONTEXT of each decl to the TRANSLATION_UNIT_DECL.
+            This makes same_translation_unit_p work, and causes
+            static declarations to be given disambiguating suffixes.  */
+         if (scope == file_scope && num_in_fnames > 1)
+           {
+             DECL_CONTEXT (p) = context;
+             if (TREE_CODE (p) == TYPE_DECL)
+               set_type_context (TREE_TYPE (p), context);
+           }
 
          /* Fall through.  */
          /* Parameters go in DECL_ARGUMENTS, not BLOCK_VARS, and have
@@ -761,7 +807,7 @@ pop_scope (void)
        }
     }
 
-  
+
   /* Dispose of the block that we just made inside some higher level.  */
   if ((scope->function_body || scope == file_scope) && context)
     {
@@ -795,9 +841,9 @@ void
 push_file_scope (void)
 {
   tree decl;
-  tree file_decl = build_decl (TRANSLATION_UNIT_DECL, 0, 0);
-  TREE_CHAIN (file_decl) = current_file_decl;
-  current_file_decl = file_decl;
+
+  if (file_scope)
+    return;
 
   push_scope ();
   file_scope = current_scope;
@@ -805,7 +851,8 @@ push_file_scope (void)
   start_fname_decls ();
 
   for (decl = visible_builtins; decl; decl = TREE_CHAIN (decl))
-    bind (DECL_NAME (decl), decl, file_scope);
+    bind (DECL_NAME (decl), decl, file_scope,
+         /*invisible=*/false, /*nested=*/true);
 }
 
 void
@@ -821,17 +868,18 @@ pop_file_scope (void)
      still works without it.  */
   finish_fname_decls ();
 
-  /* Kludge: don't actually pop the file scope if generating a
-     precompiled header, so that macros and local symbols are still
-     visible to the PCH generator.  */
+  /* This is the point to write out a PCH if we're doing that.
+     In that case we do not want to do anything else.  */
   if (pch_file)
-    return;
+    {
+      c_common_write_pch ();
+      return;
+    }
 
-  /* And pop off the file scope.  */
+  /* Pop off the file scope and close this translation unit.  */
   pop_scope ();
   file_scope = 0;
-
-  cpp_undef_all (parse_in);
+  cgraph_finalize_compilation_unit ();
 }
 
 /* Insert BLOCK at the end of the list of subblocks of the current
@@ -858,7 +906,7 @@ pushtag (tree name, tree type)
   /* Record the identifier as the type's name if it has none.  */
   if (name && !TYPE_NAME (type))
     TYPE_NAME (type) = name;
-  bind (name, type, current_scope);
+  bind (name, type, current_scope, /*invisible=*/false, /*nested=*/false);
 
   /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the
      tagged type we just added to the current scope.  This fake
@@ -924,7 +972,7 @@ diagnose_arglist_conflict (tree newdecl, tree olddecl,
   tree t;
 
   if (TREE_CODE (olddecl) != FUNCTION_DECL
-      || !comptypes (TREE_TYPE (oldtype), TREE_TYPE (newtype), COMPARE_STRICT)
+      || !comptypes (TREE_TYPE (oldtype), TREE_TYPE (newtype))
       || !((TYPE_ARG_TYPES (oldtype) == 0 && DECL_INITIAL (olddecl) == 0)
           ||
           (TYPE_ARG_TYPES (newtype) == 0 && DECL_INITIAL (newdecl) == 0)))
@@ -996,7 +1044,7 @@ validate_proto_after_old_defn (tree newdecl, tree newtype, tree oldtype)
 
       /* Type for passing arg must be consistent with that declared
         for the arg.  */
-      else if (! comptypes (oldargtype, newargtype, COMPARE_STRICT))
+      else if (! comptypes (oldargtype, newargtype))
        {
          error ("%Jprototype for '%D' declares arg %d with incompatible type",
                 newdecl, newdecl, i);
@@ -1078,7 +1126,7 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl,
       return false;
     }
 
-  if (!comptypes (oldtype, newtype, COMPARE_STRICT))
+  if (!comptypes (oldtype, newtype))
     {
       if (TREE_CODE (olddecl) == FUNCTION_DECL
          && DECL_BUILT_IN (olddecl) && !C_DECL_DECLARED_BUILTIN (olddecl))
@@ -1087,7 +1135,7 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl,
             This is for the ffs and fprintf builtins.  */
          tree trytype = match_builtin_function_types (newtype, oldtype);
 
-         if (trytype && comptypes (newtype, trytype, COMPARE_STRICT))
+         if (trytype && comptypes (newtype, trytype))
            *oldtypep = oldtype = trytype;
          else
            {
@@ -1100,7 +1148,7 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl,
            }
        }
       else if (TREE_CODE (olddecl) == FUNCTION_DECL
-              && DECL_SOURCE_LINE (olddecl) == 0)
+              && DECL_IS_BUILTIN (olddecl))
        {
          /* A conflicting function declaration for a predeclared
             function that isn't actually built in.  Objective C uses
@@ -1126,7 +1174,10 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl,
        }
       else
        {
-         error ("%Jconflicting types for '%D'", newdecl, newdecl);
+         if (TYPE_QUALS (newtype) != TYPE_QUALS (oldtype))
+           error ("%J conflicting type qualifiers for '%D'", newdecl, newdecl);
+         else
+           error ("%Jconflicting types for '%D'", newdecl, newdecl);
          diagnose_arglist_conflict (newdecl, olddecl, newtype, oldtype);
          locate_old_decl (olddecl, error);
          return false;
@@ -1140,7 +1191,7 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl,
     {
       if (DECL_IN_SYSTEM_HEADER (newdecl) || DECL_IN_SYSTEM_HEADER (olddecl))
        return true;  /* Allow OLDDECL to continue in use.  */
-      
+
       error ("%Jredefinition of typedef '%D'", newdecl, newdecl);
       locate_old_decl (olddecl, error);
       return false;
@@ -1170,14 +1221,15 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl,
          /* Discard the old built-in function.  */
          return false;
        }
-      
+
       if (DECL_INITIAL (newdecl))
        {
          if (DECL_INITIAL (olddecl)
              && !(DECL_DECLARED_INLINE_P (olddecl)
                   && DECL_EXTERNAL (olddecl)
                   && !(DECL_DECLARED_INLINE_P (newdecl)
-                       && DECL_EXTERNAL (newdecl))))
+                       && DECL_EXTERNAL (newdecl)
+                       && same_translation_unit_p (olddecl, newdecl))))
            {
              error ("%Jredefinition of '%D'", newdecl, newdecl);
              locate_old_decl (olddecl, error);
@@ -1194,33 +1246,47 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl,
          locate_old_decl (olddecl, error);
          return false;
        }
-      /* Mismatched non-static and static is considered poor style.
-         We only diagnose static then non-static if -Wtraditional,
-        because it is the most convenient way to get some effects
-        (see e.g.  what unwind-dw2-fde-glibc.c does to the definition
-        of _Unwind_Find_FDE in unwind-dw2-fde.c).  Revisit?  */
+      /* A non-static declaration (even an "extern") followed by a
+        static declaration is undefined behavior per C99 6.2.2p3-5,7.
+        The same is true for a static forward declaration at block
+        scope followed by a non-static declaration/definition at file
+        scope.  Static followed by non-static at the same scope is
+        not undefined behavior, and is the most convenient way to get
+        some effects (see e.g.  what unwind-dw2-fde-glibc.c does to
+        the definition of _Unwind_Find_FDE in unwind-dw2-fde.c), but
+        we do diagnose it if -Wtraditional. */
       if (TREE_PUBLIC (olddecl) && !TREE_PUBLIC (newdecl))
        {
-         /* A static function declaration for a predeclared function
-            that isn't actually built in, silently overrides the
-            default.  Objective C uses these.  See also above.
-            FIXME: Make Objective C use normal builtins.  */
-         if (TREE_CODE (olddecl) == FUNCTION_DECL
-             && DECL_SOURCE_LINE (olddecl) == 0)
-           return false;
-         else
+         /* Two exceptions to the rule.  If olddecl is an extern
+            inline, or a predeclared function that isn't actually
+            built in, newdecl silently overrides olddecl.  The latter
+            occur only in Objective C; see also above.  (FIXME: Make
+            Objective C use normal builtins.)  */
+         if (!DECL_IS_BUILTIN (olddecl)
+             && !(DECL_EXTERNAL (olddecl)
+                  && DECL_DECLARED_INLINE_P (olddecl)))
            {
-             warning ("%Jstatic declaration of '%D' follows "
-                      "non-static declaration", newdecl, newdecl);
-             warned = true;
+             error ("%Jstatic declaration of '%D' follows "
+                    "non-static declaration", newdecl, newdecl);
+             locate_old_decl (olddecl, error);
            }
+         return false;
        }
-      else if (TREE_PUBLIC (newdecl) && !TREE_PUBLIC (olddecl)
-              && warn_traditional)
+      else if (TREE_PUBLIC (newdecl) && !TREE_PUBLIC (olddecl))
        {
-         warning ("%Jnon-static declaration of '%D' follows "
-                  "static declaration", newdecl, newdecl);
-         warned = true;
+         if (DECL_CONTEXT (olddecl))
+           {
+             error ("%Jnon-static declaration of '%D' follows "
+                    "static declaration", newdecl, newdecl);
+             locate_old_decl (olddecl, error);
+             return false;
+           }
+         else if (warn_traditional)
+           {
+             warning ("%Jnon-static declaration of '%D' follows "
+                      "static declaration", newdecl, newdecl);
+             warned = true;
+           }
        }
     }
   else if (TREE_CODE (newdecl) == VAR_DECL)
@@ -1248,13 +1314,27 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl,
          return false;
        }
 
-      /* Objects declared at file scope: if at least one is 'extern',
-        it's fine (6.2.2p4); otherwise the linkage must agree (6.2.2p7).  */
-      if (DECL_FILE_SCOPE_P (newdecl))
+      /* Objects declared at file scope: if the first declaration had
+        external linkage (even if it was an external reference) the
+        second must have external linkage as well, or the behavior is
+        undefined.  If the first declaration had internal linkage, then
+        the second must too, or else be an external reference (in which
+        case the composite declaration still has internal linkage).
+        As for function declarations, we warn about the static-then-
+        extern case only for -Wtraditional.  See generally 6.2.2p3-5,7.  */
+      if (DECL_FILE_SCOPE_P (newdecl)
+         && TREE_PUBLIC (newdecl) != TREE_PUBLIC (olddecl))
        {
-         if (!DECL_EXTERNAL (newdecl)
-             && !DECL_EXTERNAL (olddecl)
-             && TREE_PUBLIC (newdecl) != TREE_PUBLIC (olddecl))
+         if (DECL_EXTERNAL (newdecl))
+           {
+             if (warn_traditional)
+               {
+                 warning ("%Jnon-static declaration of '%D' follows "
+                          "static declaration", newdecl, newdecl);
+                 warned = true;
+               }
+           }
+         else
            {
              if (TREE_PUBLIC (newdecl))
                error ("%Jnon-static declaration of '%D' follows "
@@ -1269,7 +1349,8 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl,
        }
       /* Two objects with the same name declared at the same block
         scope must both be external references (6.7p3).  */
-      else if (DECL_CONTEXT (newdecl) == DECL_CONTEXT (olddecl)
+      else if (!DECL_FILE_SCOPE_P (newdecl)
+              && DECL_CONTEXT (newdecl) == DECL_CONTEXT (olddecl)
               && (!DECL_EXTERNAL (newdecl) || !DECL_EXTERNAL (olddecl)))
        {
          if (DECL_EXTERNAL (newdecl))
@@ -1318,8 +1399,11 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl,
 
       /* Inline declaration after use or definition.
         ??? Should we still warn about this now we have unit-at-a-time
-        mode and can get it right?  */
-      if (DECL_DECLARED_INLINE_P (newdecl) && !DECL_DECLARED_INLINE_P (olddecl))
+        mode and can get it right?
+        Definitely don't complain if the decls are in different translation
+        units.  */
+      if (DECL_DECLARED_INLINE_P (newdecl) && !DECL_DECLARED_INLINE_P (olddecl)
+         && same_translation_unit_p (olddecl, newdecl))
        {
          if (TREE_USED (olddecl))
            {
@@ -1353,28 +1437,6 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl,
          locate_old_decl (olddecl, error);
          return false;
        }
-
-      /* These bits are only type qualifiers when applied to objects.  */
-      if (TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl))
-       {
-         if (TREE_THIS_VOLATILE (newdecl))
-           pedwarn ("%Jvolatile declaration of '%D' follows "
-                    "non-volatile declaration", newdecl, newdecl);
-         else
-           pedwarn ("%Jnon-volatile declaration of '%D' follows "
-                    "volatile declaration", newdecl, newdecl);
-         pedwarned = true;
-       }
-      if (TREE_READONLY (newdecl) != TREE_READONLY (olddecl))
-       {
-         if (TREE_READONLY (newdecl))
-           pedwarn ("%Jconst declaration of '%D' follows "
-                    "non-const declaration", newdecl, newdecl);
-         else
-           pedwarn ("%Jnon-const declaration of '%D' follows "
-                    "const declaration", newdecl, newdecl);
-         pedwarned = true;
-       }
     }
 
   /* Optional warning for completely redundant decls.  */
@@ -1440,7 +1502,7 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
   /* Merge the data types specified in the two decls.  */
   TREE_TYPE (newdecl)
     = TREE_TYPE (olddecl)
-    = common_type (newtype, oldtype);
+    = composite_type (newtype, oldtype);
 
   /* Lay the type out, unless already done.  */
   if (oldtype != TREE_TYPE (newdecl))
@@ -1623,18 +1685,17 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
        }
     }
 
-  /* This bit must not get wiped out.  */
-  C_DECL_IN_EXTERNAL_SCOPE (newdecl) |= C_DECL_IN_EXTERNAL_SCOPE (olddecl);
-
   /* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
-     But preserve OLDDECL's DECL_UID.  */
+     But preserve OLDDECL's DECL_UID and DECL_CONTEXT.  */
   {
     unsigned olddecl_uid = DECL_UID (olddecl);
+    tree olddecl_context = DECL_CONTEXT (olddecl);
 
     memcpy ((char *) olddecl + sizeof (struct tree_common),
            (char *) newdecl + sizeof (struct tree_common),
            sizeof (struct tree_decl) - sizeof (struct tree_common));
     DECL_UID (olddecl) = olddecl_uid;
+    DECL_CONTEXT (olddecl) = olddecl_context;
   }
 
   /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
@@ -1657,7 +1718,7 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
 static bool
 duplicate_decls (tree newdecl, tree olddecl)
 {
-  tree newtype, oldtype;
+  tree newtype = NULL, oldtype = NULL;
 
   if (!diagnose_mismatched_decls (newdecl, olddecl, &newtype, &oldtype))
     return false;
@@ -1665,7 +1726,7 @@ duplicate_decls (tree newdecl, tree olddecl)
   merge_decls (newdecl, olddecl, newtype, oldtype);
   return true;
 }
-  
+
 \f
 /* Check whether decl-node NEW shadows an existing declaration.  */
 static void
@@ -1676,7 +1737,7 @@ warn_if_shadowing (tree new)
   /* Shadow warnings wanted?  */
   if (!warn_shadow
       /* No shadow warnings for internally generated vars.  */
-      || DECL_SOURCE_LINE (new) == 0
+      || DECL_IS_BUILTIN (new)
       /* No shadow warnings for vars made for inlining.  */
       || DECL_FROM_INLINE (new)
       /* Don't warn about the parm names in function declarator
@@ -1687,10 +1748,9 @@ warn_if_shadowing (tree new)
       || (TREE_CODE (new) == PARM_DECL && current_scope->outer->parm_flag))
     return;
 
-  /* Is anything being shadowed?  Do not be confused by a second binding
-     to the same decl in the externals scope.  */
+  /* Is anything being shadowed?  Invisible decls do not count.  */
   for (b = I_SYMBOL_BINDING (DECL_NAME (new)); b; b = b->shadowed)
-    if (b->decl && b->decl != new && b->contour != external_scope)
+    if (b->decl && b->decl != new && !b->invisible)
       {
        tree old = b->decl;
 
@@ -1760,7 +1820,7 @@ warn_if_shadowing (tree new)
 static void
 clone_underlying_type (tree x)
 {
-  if (DECL_SOURCE_LINE (x) == 0)
+  if (DECL_IS_BUILTIN (x))
     {
       if (TYPE_NAME (TREE_TYPE (x)) == 0)
        TYPE_NAME (TREE_TYPE (x)) = x;
@@ -1791,25 +1851,24 @@ pushdecl (tree x)
   tree name = DECL_NAME (x);
   struct c_scope *scope = current_scope;
   struct c_binding *b;
+  bool nested = false;
 
   /* Functions need the lang_decl data.  */
   if (TREE_CODE (x) == FUNCTION_DECL && ! DECL_LANG_SPECIFIC (x))
     DECL_LANG_SPECIFIC (x) = ggc_alloc_cleared (sizeof (struct lang_decl));
 
-  /* A local extern declaration for a function doesn't constitute nesting.
-     A local auto declaration does, since it's a forward decl
-     for a nested function coming later.  */
-  if (current_function_decl == NULL
-      || ((TREE_CODE (x) == FUNCTION_DECL || TREE_CODE (x) == VAR_DECL)
-         && DECL_INITIAL (x) == 0 && DECL_EXTERNAL (x)))
-    DECL_CONTEXT (x) = current_file_decl;
-  else
+  /* Must set DECL_CONTEXT for everything not at file scope or
+     DECL_FILE_SCOPE_P won't work.  Local externs don't count
+     unless they have initializers (which generate code).  */
+  if (current_function_decl
+      && ((TREE_CODE (x) != FUNCTION_DECL && TREE_CODE (x) != VAR_DECL)
+         || DECL_INITIAL (x) || !DECL_EXTERNAL (x)))
     DECL_CONTEXT (x) = current_function_decl;
 
   /* Anonymous decls are just inserted in the scope.  */
   if (!name)
     {
-      bind (name, x, scope);
+      bind (name, x, scope, /*invisible=*/false, /*nested=*/false);
       return x;
     }
 
@@ -1821,7 +1880,7 @@ pushdecl (tree x)
      diagnostics).  In particular, we should not consider possible
      duplicates in the external scope, or shadowing.  */
   b = I_SYMBOL_BINDING (name);
-  if (b && b->contour == scope)
+  if (b && B_IN_SCOPE (b, scope))
     {
       if (duplicate_decls (x, b->decl))
        return b->decl;
@@ -1846,10 +1905,9 @@ pushdecl (tree x)
       if (warn_nested_externs
          && scope != file_scope
          && !DECL_IN_SYSTEM_HEADER (x))
-       warning ("nested extern declaration of `%s'",
-                IDENTIFIER_POINTER (name));
+       warning ("nested extern declaration of '%D'", x);
 
-      while (b && b->contour != external_scope)
+      while (b && !B_IN_EXTERNAL_SCOPE (b))
        b = b->shadowed;
 
       /* The point of the same_translation_unit_p check here is,
@@ -1858,19 +1916,42 @@ pushdecl (tree x)
         they are in different translation units.  In any case,
         the static does not go in the externals scope.  */
       if (b
-         && (DECL_EXTERNAL (x) || TREE_PUBLIC (x)
-             || same_translation_unit_p (x, b->decl))
+         && (TREE_PUBLIC (x) || same_translation_unit_p (x, b->decl))
          && duplicate_decls (x, b->decl))
        {
-         bind (name, b->decl, scope);
+         bind (name, b->decl, scope, /*invisible=*/false, /*nested=*/true);
          return b->decl;
        }
-      else if (DECL_EXTERNAL (x) || TREE_PUBLIC (x))
+      else if (TREE_PUBLIC (x))
        {
-         C_DECL_IN_EXTERNAL_SCOPE (x) = 1;
-         bind (name, x, external_scope);
+         bind (name, x, external_scope, /*invisible=*/true, /*nested=*/false);
+         nested = true;
        }
     }
+  /* Similarly, a declaration of a function with static linkage at
+     block scope must be checked against any existing declaration
+     of that function at file scope.  */
+  else if (TREE_CODE (x) == FUNCTION_DECL && scope != file_scope
+          && !TREE_PUBLIC (x) && !DECL_INITIAL (x))
+    {
+      if (warn_nested_externs && !DECL_IN_SYSTEM_HEADER (x))
+       warning ("nested static declaration of '%D'", x);
+
+      while (b && !B_IN_FILE_SCOPE (b))
+       b = b->shadowed;
+
+      if (b && same_translation_unit_p (x, b->decl)
+         && duplicate_decls (x, b->decl))
+       {
+         bind (name, b->decl, scope, /*invisible=*/false, /*nested=*/true);
+         return b->decl;
+       }
+      else
+       {
+         bind (name, x, file_scope, /*invisible=*/true, /*nested=*/false);
+         nested = true;
+       }
+    }      
 
   warn_if_shadowing (x);
 
@@ -1878,7 +1959,7 @@ pushdecl (tree x)
   if (TREE_CODE (x) == TYPE_DECL)
     clone_underlying_type (x);
 
-  bind (name, x, scope);
+  bind (name, x, scope, /*invisible=*/false, nested);
 
   /* If x's type is incomplete because it's based on a
      structure or union which has not yet been fully declared,
@@ -1918,6 +1999,7 @@ tree
 pushdecl_top_level (tree x)
 {
   tree name;
+  bool nested = false;
 
   if (TREE_CODE (x) != VAR_DECL)
     abort ();
@@ -1927,14 +2009,13 @@ pushdecl_top_level (tree x)
   if (I_SYMBOL_BINDING (name))
     abort ();
 
-  DECL_CONTEXT (x) = current_file_decl;
-  if (DECL_EXTERNAL (x) || TREE_PUBLIC (x))
+  if (TREE_PUBLIC (x))
     {
-      C_DECL_IN_EXTERNAL_SCOPE (x) = 1;
-      bind (name, x, external_scope);
+      bind (name, x, external_scope, /*invisible=*/true, /*nested=*/false);
+      nested = true;
     }
   if (file_scope)
-    bind (name, x, file_scope);
+    bind (name, x, file_scope, /*invisible=*/false, nested);
 
   return x;
 }
@@ -1971,9 +2052,10 @@ implicitly_declare (tree functionid)
         in the external scope because they're pushed before the file
         scope gets created.  Catch this here and rebind them into the
         file scope.  */
-      if (!DECL_BUILT_IN (decl) && DECL_SOURCE_LINE (decl) == 0)
+      if (!DECL_BUILT_IN (decl) && DECL_IS_BUILTIN (decl))
        {
-         bind (functionid, decl, file_scope);
+         bind (functionid, decl, file_scope,
+               /*invisible=*/false, /*nested=*/true);
          return decl;
        }
       else
@@ -1987,7 +2069,8 @@ implicitly_declare (tree functionid)
              implicit_decl_warning (functionid, decl);
              C_DECL_IMPLICIT (decl) = 1;
            }
-         bind (functionid, decl, current_scope);
+         bind (functionid, decl, current_scope,
+               /*invisible=*/false, /*nested=*/true);
          return decl;
        }
     }
@@ -2047,7 +2130,7 @@ undeclared_variable (tree id)
          will be nonnull but current_function_scope will be null.  */
       scope = current_function_scope ? current_function_scope : current_scope;
     }
-  bind (id, error_mark_node, scope);
+  bind (id, error_mark_node, scope, /*invisible=*/false, /*nested=*/false);
 }
 \f
 /* Subroutine of lookup_label, declare_label, define_label: construct a
@@ -2101,7 +2184,8 @@ lookup_label (tree name)
   label = make_label (name, input_location);
 
   /* Ordinary labels go in the current function scope.  */
-  bind (name, label, current_function_scope);
+  bind (name, label, current_function_scope,
+       /*invisible=*/false, /*nested=*/false);
   return label;
 }
 
@@ -2109,10 +2193,6 @@ lookup_label (tree name)
    any that may be inherited from containing functions or containing
    scopes.  This is called for __label__ declarations.  */
 
-/* Note that valid use, if the label being shadowed comes from another
-   scope in the same function, requires calling declare_nonlocal_label
-   right away.  (Is this still true?  -zw 2003-07-17)  */
-
 tree
 declare_label (tree name)
 {
@@ -2121,7 +2201,7 @@ declare_label (tree name)
 
   /* Check to make sure that the label hasn't already been declared
      at this scope */
-  if (b && b->contour == current_scope)
+  if (b && B_IN_CURRENT_SCOPE (b))
     {
       error ("duplicate label declaration `%s'", IDENTIFIER_POINTER (name));
       locate_old_decl (b->decl, error);
@@ -2134,7 +2214,8 @@ declare_label (tree name)
   C_DECLARED_LABEL_FLAG (label) = 1;
 
   /* Declared labels go in the current scope.  */
-  bind (name, label, current_scope);
+  bind (name, label, current_scope,
+       /*invisible=*/false, /*nested=*/false);
   return label;
 }
 
@@ -2174,7 +2255,8 @@ define_label (location_t location, tree name)
       label = make_label (name, location);
 
       /* Ordinary labels go in the current function scope.  */
-      bind (name, label, current_function_scope);
+      bind (name, label, current_function_scope,
+           /*invisible=*/false, /*nested=*/false);
     }
 
   if (warn_traditional && !in_system_header && lookup_name (name))
@@ -2210,9 +2292,9 @@ lookup_tag (enum tree_code code, tree name, int thislevel_only)
       /* For our purposes, a tag in the external scope is the same as
         a tag in the file scope.  (Primarily relevant to Objective-C
         and its builtin structure tags, which get pushed before the
-        file scope is created.)  */ 
-      if (b->contour == current_scope
-         || (current_scope == file_scope && b->contour == external_scope))
+        file scope is created.)  */
+      if (B_IN_CURRENT_SCOPE (b)
+         || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
        thislevel = 1;
     }
 
@@ -2260,7 +2342,7 @@ tree
 lookup_name (tree name)
 {
   struct c_binding *b = I_SYMBOL_BINDING (name);
-  if (b && (b->contour != external_scope || TREE_CODE (b->decl) == TYPE_DECL))
+  if (b && !b->invisible)
     return b->decl;
   return 0;
 }
@@ -2273,7 +2355,7 @@ lookup_name_in_scope (tree name, struct c_scope *scope)
   struct c_binding *b;
 
   for (b = I_SYMBOL_BINDING (name); b; b = b->shadowed)
-    if (b->contour == scope)
+    if (B_IN_SCOPE (b, scope))
       return b->decl;
   return 0;
 }
@@ -2302,8 +2384,12 @@ c_init_decl_processing (void)
   /* Declarations from c_common_nodes_and_builtins must not be associated
      with this input file, lest we get differences between using and not
      using preprocessed headers.  */
-  input_location.file = "<internal>";
+#ifdef USE_MAPPED_LOCATION
+  input_location = BUILTINS_LOCATION;
+#else
+  input_location.file = "<built-in>";
   input_location.line = 0;
+#endif
 
   build_common_tree_nodes (flag_signed_char);
 
@@ -2357,6 +2443,7 @@ c_make_fname_decl (tree id, int type_dep)
   DECL_ARTIFICIAL (decl) = 1;
 
   init = build_string (length + 1, name);
+  free ((char *) name);
   TREE_TYPE (init) = type;
   DECL_INITIAL (decl) = init;
 
@@ -2365,7 +2452,8 @@ c_make_fname_decl (tree id, int type_dep)
   if (current_function_decl)
     {
       DECL_CONTEXT (decl) = current_function_decl;
-      bind (id, decl, current_function_scope);
+      bind (id, decl, current_function_scope,
+           /*invisible=*/false, /*nested=*/false);
     }
 
   finish_decl (decl, init, NULL_TREE);
@@ -2396,14 +2484,12 @@ builtin_function (const char *name, tree type, int function_code,
   DECL_FUNCTION_CODE (decl) = function_code;
   if (library_name)
     SET_DECL_ASSEMBLER_NAME (decl, get_identifier (library_name));
-  make_decl_rtl (decl, NULL);
 
   /* Should never be called on a symbol with a preexisting meaning.  */
   if (I_SYMBOL_BINDING (id))
     abort ();
 
-  C_DECL_IN_EXTERNAL_SCOPE (decl) = 1;
-  bind (id, decl, external_scope);
+  bind (id, decl, external_scope, /*invisible=*/true, /*nested=*/false);
 
   /* Builtins in the implementation namespace are made visible without
      needing to be explicitly declared.  See push_file_scope.  */
@@ -2523,7 +2609,7 @@ tree
 build_array_declarator (tree expr, tree quals, int static_p, int vla_unspec_p)
 {
   tree decl;
-  decl = build_nt (ARRAY_REF, NULL_TREE, expr);
+  decl = build_nt (ARRAY_REF, NULL_TREE, expr, NULL_TREE, NULL_TREE);
   TREE_TYPE (decl) = quals;
   TREE_STATIC (decl) = (static_p ? 1 : 0);
   if (pedantic && !flag_isoc99)
@@ -2727,7 +2813,7 @@ start_decl (tree declarator, tree declspecs, int initialized, tree attributes)
          for (; args; args = TREE_CHAIN (args))
            {
              tree type = TREE_TYPE (args);
-             if (INTEGRAL_TYPE_P (type)
+             if (type && INTEGRAL_TYPE_P (type)
                  && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
                DECL_ARG_TYPE (args) = integer_type_node;
            }
@@ -2880,18 +2966,11 @@ finish_decl (tree decl, tree init, tree asmspec_tree)
        {
          tree builtin = built_in_decls [DECL_FUNCTION_CODE (decl)];
          SET_DECL_RTL (builtin, NULL_RTX);
-         SET_DECL_ASSEMBLER_NAME (builtin, get_identifier (starred));
-#ifdef TARGET_MEM_FUNCTIONS
+         change_decl_assembler_name (builtin, get_identifier (starred));
          if (DECL_FUNCTION_CODE (decl) == BUILT_IN_MEMCPY)
            init_block_move_fn (starred);
          else if (DECL_FUNCTION_CODE (decl) == BUILT_IN_MEMSET)
            init_block_clear_fn (starred);
-#else
-         if (DECL_FUNCTION_CODE (decl) == BUILT_IN_BCOPY)
-           init_block_move_fn (starred);
-         else if (DECL_FUNCTION_CODE (decl) == BUILT_IN_BZERO)
-           init_block_clear_fn (starred);
-#endif
        }
       SET_DECL_RTL (decl, NULL_RTX);
       change_decl_assembler_name (decl, get_identifier (starred));
@@ -2932,7 +3011,7 @@ finish_decl (tree decl, tree init, tree asmspec_tree)
                 in a particular register.  */
              if (C_DECL_REGISTER (decl))
                {
-                 DECL_C_HARD_REGISTER (decl) = 1;
+                 DECL_HARD_REGISTER (decl) = 1;
                  /* This cannot be done for a structure with volatile
                     fields, on which DECL_REGISTER will have been
                     reset.  */
@@ -2955,7 +3034,7 @@ finish_decl (tree decl, tree init, tree asmspec_tree)
            }
 
          if (TREE_CODE (decl) != FUNCTION_DECL)
-           add_decl_stmt (decl);
+           add_stmt (build_stmt (DECL_EXPR, decl));
        }
 
       if (!DECL_FILE_SCOPE_P (decl))
@@ -2976,10 +3055,16 @@ finish_decl (tree decl, tree init, tree asmspec_tree)
 
   /* If this was marked 'used', be sure it will be output.  */
   if (lookup_attribute ("used", DECL_ATTRIBUTES (decl)))
-    mark_referenced (DECL_ASSEMBLER_NAME (decl));
+    mark_decl_referenced (decl);
 
   if (TREE_CODE (decl) == TYPE_DECL)
-    rest_of_decl_compilation (decl, NULL, DECL_FILE_SCOPE_P (decl), 0);
+    {
+      if (!DECL_FILE_SCOPE_P (decl)
+         && variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
+       add_stmt (build_stmt (DECL_EXPR, decl));
+
+      rest_of_decl_compilation (decl, NULL, DECL_FILE_SCOPE_P (decl), 0);
+    }
 
   /* At the end of a declaration, throw away any variable type sizes
      of types defined inside that declaration.  There is no use
@@ -2993,8 +3078,6 @@ finish_decl (tree decl, tree init, tree asmspec_tree)
       tree attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl));
       if (attr)
        {
-         static bool eh_initialized_p;
-
          tree cleanup_id = TREE_VALUE (TREE_VALUE (attr));
          tree cleanup_decl = lookup_name (cleanup_id);
          tree cleanup;
@@ -3006,11 +3089,12 @@ finish_decl (tree decl, tree init, tree asmspec_tree)
 
          /* Don't warn about decl unused; the cleanup uses it.  */
          TREE_USED (decl) = 1;
+         TREE_USED (cleanup_decl) = 1;
 
          /* Initialize EH, if we've been told to do so.  */
-         if (flag_exceptions && !eh_initialized_p)
+         if (flag_exceptions && !c_eh_initialized_p)
            {
-             eh_initialized_p = true;
+             c_eh_initialized_p = true;
              eh_personality_libfunc
                = init_one_libfunc (USING_SJLJ_EXCEPTIONS
                                    ? "__gcc_personality_sj0"
@@ -3018,7 +3102,7 @@ finish_decl (tree decl, tree init, tree asmspec_tree)
              using_eh_for_cleanups ();
            }
 
-         add_stmt (build_stmt (CLEANUP_STMT, decl, cleanup));
+         push_cleanup (decl, cleanup, false);
        }
     }
 }
@@ -3031,11 +3115,6 @@ push_parm_decl (tree parm)
 {
   tree decl;
 
-  /* Don't attempt to expand sizes while parsing this decl.
-     (We can get here with i_s_e 1 somehow from Objective-C.)  */
-  int save_immediate_size_expand = immediate_size_expand;
-  immediate_size_expand = 0;
-
   decl = grokdeclarator (TREE_VALUE (TREE_PURPOSE (parm)),
                         TREE_PURPOSE (TREE_PURPOSE (parm)),
                         PARM, 0, NULL);
@@ -3044,8 +3123,6 @@ push_parm_decl (tree parm)
   decl = pushdecl (decl);
 
   finish_decl (decl, NULL_TREE, NULL_TREE);
-
-  immediate_size_expand = save_immediate_size_expand;
 }
 
 /* Mark all the parameter declarations to date as forward decls.
@@ -3079,7 +3156,7 @@ build_compound_literal (tree type, tree init)
 {
   /* We do not use start_decl here because we have a type, not a declarator;
      and do not use finish_decl because the decl should be stored inside
-     the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_STMT.  */
+     the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_EXPR.  */
   tree decl = build_decl (VAR_DECL, NULL_TREE, type);
   tree complit;
   tree stmt;
@@ -3089,7 +3166,7 @@ build_compound_literal (tree type, tree init)
   DECL_CONTEXT (decl) = current_function_decl;
   TREE_USED (decl) = 1;
   TREE_TYPE (decl) = type;
-  TREE_READONLY (decl) = TREE_READONLY (type);
+  TREE_READONLY (decl) = TYPE_READONLY (type);
   store_init_value (decl, init);
 
   if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type))
@@ -3103,7 +3180,7 @@ build_compound_literal (tree type, tree init)
   if (type == error_mark_node || !COMPLETE_TYPE_P (type))
     return error_mark_node;
 
-  stmt = build_stmt (DECL_STMT, decl);
+  stmt = build_stmt (DECL_EXPR, decl);
   complit = build1 (COMPOUND_LITERAL_EXPR, TREE_TYPE (decl), stmt);
   TREE_SIDE_EFFECTS (complit) = 1;
 
@@ -3294,10 +3371,14 @@ check_bitfield_type_and_width (tree *type, tree *width, const char *orig_name)
   else
     w = tree_low_cst (*width, 1);
 
-  if (TREE_CODE (*type) == ENUMERAL_TYPE
-      && (w < min_precision (TYPE_MIN_VALUE (*type), TREE_UNSIGNED (*type))
-         || w < min_precision (TYPE_MAX_VALUE (*type), TREE_UNSIGNED (*type))))
-    warning ("`%s' is narrower than values of its type", name);
+  if (TREE_CODE (*type) == ENUMERAL_TYPE)
+    {
+      struct lang_type *lt = TYPE_LANG_SPECIFIC (*type);
+      if (!lt
+          || w < min_precision (lt->enum_min, TYPE_UNSIGNED (*type))
+         || w < min_precision (lt->enum_max, TYPE_UNSIGNED (*type)))
+       warning ("`%s' is narrower than values of its type", name);
+    }
 }
 \f
 /* Given declspecs and a declarator,
@@ -3912,7 +3993,7 @@ grokdeclarator (tree declarator, tree declspecs,
              type = error_mark_node;
            }
 
-         if (pedantic && flexible_array_type_p (type))
+         if (pedantic && !in_system_header && flexible_array_type_p (type))
            pedwarn ("invalid use of structure with flexible array member");
 
          if (size == error_mark_node)
@@ -3996,20 +4077,7 @@ grokdeclarator (tree declarator, tree declspecs,
                    }
 
                  if (size_varies)
-                   {
-                     /* We must be able to distinguish the
-                        SAVE_EXPR_CONTEXT for the variably-sized type
-                        so that we can set it correctly in
-                        set_save_expr_context.  The convention is
-                        that all SAVE_EXPRs that need to be reset
-                        have NULL_TREE for their SAVE_EXPR_CONTEXT.  */
-                     tree cfd = current_function_decl;
-                     if (decl_context == PARM)
-                       current_function_decl = NULL_TREE;
-                     itype = variable_size (itype);
-                     if (decl_context == PARM)
-                       current_function_decl = cfd;
-                   }
+                   itype = variable_size (itype);
                  itype = build_index_type (itype);
                }
            }
@@ -4048,6 +4116,11 @@ grokdeclarator (tree declarator, tree declspecs,
              TYPE_SIZE (type) = bitsize_zero_node;
              TYPE_SIZE_UNIT (type) = size_zero_node;
            }
+         else if (declarator && TREE_CODE (declarator) == INDIRECT_REF)
+           /* We can never complete an array type which is the target of a
+              pointer, so go ahead and lay it out.  */
+           layout_type (type);
+
          if (decl_context != PARM
              && (array_ptr_quals != NULL_TREE || array_parm_static))
            {
@@ -4404,14 +4477,6 @@ grokdeclarator (tree declarator, tree declspecs,
       }
     else if (TREE_CODE (type) == FUNCTION_TYPE)
       {
-       /* Every function declaration is "external"
-          except for those which are inside a function body
-          in which `auto' is used.
-          That is a case not specified by ANSI C,
-          and we use it for forward declarations for nested functions.  */
-       int extern_ref = (!(specbits & (1 << (int) RID_AUTO))
-                         || current_scope == file_scope);
-
        if (specbits & (1 << (int) RID_AUTO)
            && (pedantic || current_scope == file_scope))
          pedwarn ("invalid storage class for function `%s'", name);
@@ -4442,8 +4507,16 @@ grokdeclarator (tree declarator, tree declspecs,
            && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
          warning ("`noreturn' function returns non-void value");
 
-       if (extern_ref)
+       /* Every function declaration is an external reference
+          (DECL_EXTERNAL) except for those which are not at file
+          scope and are explicitly declared "auto".  This is
+          forbidden by standard C (C99 6.7.1p5) and is interpreted by
+          GCC to signify a forward declaration of a nested function.  */
+       if ((specbits & (1 << RID_AUTO)) && current_scope != file_scope)
+         DECL_EXTERNAL (decl) = 0;
+       else
          DECL_EXTERNAL (decl) = 1;
+          
        /* Record absence of global scope for `static' or `auto'.  */
        TREE_PUBLIC (decl)
          = !(specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_AUTO)));
@@ -4791,9 +4864,9 @@ get_parm_info (bool ellipsis)
            }
          break;
 
-       case ENUMERAL_TYPE: keyword = "struct"; goto tag;
+       case ENUMERAL_TYPE: keyword = "enum"; goto tag;
        case UNION_TYPE:    keyword = "union"; goto tag;
-       case RECORD_TYPE:   keyword = "enum"; goto tag;
+       case RECORD_TYPE:   keyword = "struct"; goto tag;
        tag:
          /* Types may not have tag-names, in which case the type
             appears in the bindings list with b->id NULL.  */
@@ -4821,7 +4894,7 @@ get_parm_info (bool ellipsis)
                /* The %s will be one of 'struct', 'union', or 'enum'.  */
                warning ("anonymous %s declared inside parameter list",
                         keyword);
-             
+
              if (! explained_incomplete_types)
                {
                  warning ("its scope is only this definition or declaration,"
@@ -4910,7 +4983,7 @@ xref_tag (enum tree_code code, tree name)
       TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node);
       TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
       TYPE_USER_ALIGN (ref) = 0;
-      TREE_UNSIGNED (ref) = 1;
+      TYPE_UNSIGNED (ref) = 1;
       TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
       TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
       TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
@@ -5112,9 +5185,11 @@ finish_struct (tree t, tree fieldlist, tree attributes)
     }
 
   /* Install struct as DECL_CONTEXT of each field decl.
-     Also process specified field sizes,m which is found in the DECL_INITIAL.
-     Store 0 there, except for ": 0" fields (so we can find them
-     and delete them, below).  */
+     Also process specified field sizes, found in the DECL_INITIAL,
+     storing 0 there after the type has been changed to precision equal
+     to its width, rather than the precision of the specified standard
+     type.  (Correct layout requires the original type to have been preserved
+     until now.)  */
 
   saw_named_field = 0;
   for (x = fieldlist; x; x = TREE_CHAIN (x))
@@ -5158,8 +5233,6 @@ finish_struct (tree t, tree fieldlist, tree attributes)
          SET_DECL_C_BIT_FIELD (x);
        }
 
-      DECL_INITIAL (x) = 0;
-
       /* Detect flexible array member in an invalid context.  */
       if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
          && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
@@ -5183,7 +5256,7 @@ finish_struct (tree t, tree fieldlist, tree attributes)
            }
        }
 
-      if (pedantic && TREE_CODE (t) == RECORD_TYPE
+      if (pedantic && !in_system_header && TREE_CODE (t) == RECORD_TYPE
          && flexible_array_type_p (TREE_TYPE (x)))
        pedwarn ("%Jinvalid use of structure with flexible array member", x);
 
@@ -5200,12 +5273,21 @@ finish_struct (tree t, tree fieldlist, tree attributes)
 
   layout_type (t);
 
-  /* Delete all zero-width bit-fields from the fieldlist.  */
+  /* Give bit-fields their proper types.  */
   {
     tree *fieldlistp = &fieldlist;
     while (*fieldlistp)
-      if (TREE_CODE (*fieldlistp) == FIELD_DECL && DECL_INITIAL (*fieldlistp))
-       *fieldlistp = TREE_CHAIN (*fieldlistp);
+      if (TREE_CODE (*fieldlistp) == FIELD_DECL && DECL_INITIAL (*fieldlistp)
+         && TREE_TYPE (*fieldlistp) != error_mark_node)
+       {
+         unsigned HOST_WIDE_INT width
+           = tree_low_cst (DECL_INITIAL (*fieldlistp), 1);
+         tree type = TREE_TYPE (*fieldlistp);
+         if (width != TYPE_PRECISION (type))
+           TREE_TYPE (*fieldlistp)
+             = build_nonstandard_integer_type (width, TYPE_UNSIGNED (type));
+         DECL_INITIAL (*fieldlistp) = 0;
+       }
       else
        fieldlistp = &TREE_CHAIN (*fieldlistp);
   }
@@ -5240,7 +5322,7 @@ finish_struct (tree t, tree fieldlist, tree attributes)
           ensure that this lives as long as the rest of the struct decl.
           All decls in an inline function need to be saved.  */
 
-        space = ggc_alloc (sizeof (struct lang_type));
+        space = ggc_alloc_cleared (sizeof (struct lang_type));
         space2 = ggc_alloc (sizeof (struct sorted_fields_type) + len * sizeof (tree));
 
         len = 0;
@@ -5375,9 +5457,10 @@ tree
 finish_enum (tree enumtype, tree values, tree attributes)
 {
   tree pair, tem;
-  tree minnode = 0, maxnode = 0, enum_value_type;
+  tree minnode = 0, maxnode = 0;
   int precision, unsign;
   bool toplevel = (file_scope == current_scope);
+  struct lang_type *lt;
 
   decl_attributes (&enumtype, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
 
@@ -5407,27 +5490,20 @@ finish_enum (tree enumtype, tree values, tree attributes)
                   min_precision (maxnode, unsign));
   if (TYPE_PACKED (enumtype) || precision > TYPE_PRECISION (integer_type_node))
     {
-      tree narrowest = c_common_type_for_size (precision, unsign);
-      if (narrowest == 0)
+      tem = c_common_type_for_size (precision, unsign);
+      if (tem == NULL)
        {
          warning ("enumeration values exceed range of largest integer");
-         narrowest = long_long_integer_type_node;
+         tem = long_long_integer_type_node;
        }
-
-      precision = TYPE_PRECISION (narrowest);
     }
   else
-    precision = TYPE_PRECISION (integer_type_node);
-
-  if (precision == TYPE_PRECISION (integer_type_node))
-    enum_value_type = c_common_type_for_size (precision, 0);
-  else
-    enum_value_type = enumtype;
+    tem = unsign ? unsigned_type_node : integer_type_node;
 
-  TYPE_MIN_VALUE (enumtype) = minnode;
-  TYPE_MAX_VALUE (enumtype) = maxnode;
-  TYPE_PRECISION (enumtype) = precision;
-  TREE_UNSIGNED (enumtype) = unsign;
+  TYPE_MIN_VALUE (enumtype) = TYPE_MIN_VALUE (tem);
+  TYPE_MAX_VALUE (enumtype) = TYPE_MAX_VALUE (tem);
+  TYPE_PRECISION (enumtype) = TYPE_PRECISION (tem);
+  TYPE_UNSIGNED (enumtype) = TYPE_UNSIGNED (tem);
   TYPE_SIZE (enumtype) = 0;
   layout_type (enumtype);
 
@@ -5443,6 +5519,7 @@ finish_enum (tree enumtype, tree values, tree attributes)
       for (pair = values; pair; pair = TREE_CHAIN (pair))
        {
          tree enu = TREE_PURPOSE (pair);
+         tree ini = DECL_INITIAL (enu);
 
          TREE_TYPE (enu) = enumtype;
 
@@ -5453,18 +5530,27 @@ finish_enum (tree enumtype, tree values, tree attributes)
             when comparing integers with enumerators that fit in the
             int range.  When -pedantic is given, build_enumerator()
             would have already taken care of those that don't fit.  */
-         if (int_fits_type_p (DECL_INITIAL (enu), enum_value_type))
-           DECL_INITIAL (enu) = convert (enum_value_type, DECL_INITIAL (enu));
+         if (int_fits_type_p (ini, integer_type_node))
+           tem = integer_type_node;
          else
-           DECL_INITIAL (enu) = convert (enumtype, DECL_INITIAL (enu));
+           tem = enumtype;
+         ini = convert (tem, ini);
 
+         DECL_INITIAL (enu) = ini;
          TREE_PURPOSE (pair) = DECL_NAME (enu);
-         TREE_VALUE (pair) = DECL_INITIAL (enu);
+         TREE_VALUE (pair) = ini;
        }
 
       TYPE_VALUES (enumtype) = values;
     }
 
+  /* Record the min/max values so that we can warn about bit-field
+     enumerations that are too small for the values.  */
+  lt = ggc_alloc_cleared (sizeof (struct lang_type));
+  lt->enum_min = minnode;
+  lt->enum_max = maxnode;
+  TYPE_LANG_SPECIFIC (enumtype) = lt;
+
   /* Fix up all variant types of this enum type.  */
   for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem))
     {
@@ -5479,7 +5565,8 @@ finish_enum (tree enumtype, tree values, tree attributes)
       TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
       TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype);
       TYPE_USER_ALIGN (tem) = TYPE_USER_ALIGN (enumtype);
-      TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype);
+      TYPE_UNSIGNED (tem) = TYPE_UNSIGNED (enumtype);
+      TYPE_LANG_SPECIFIC (tem) = TYPE_LANG_SPECIFIC (enumtype);
     }
 
   /* Finish debugging output for this type.  */
@@ -5551,7 +5638,7 @@ build_enumerator (tree name, tree value)
                                      TYPE_PRECISION (integer_type_node)),
                                 (TYPE_PRECISION (type)
                                  >= TYPE_PRECISION (integer_type_node)
-                                 && TREE_UNSIGNED (type)));
+                                 && TYPE_UNSIGNED (type)));
 
   decl = build_decl (CONST_DECL, name, type);
   DECL_INITIAL (decl) = convert (type, value);
@@ -5578,28 +5665,25 @@ start_function (tree declspecs, tree declarator, tree attributes)
 {
   tree decl1, old_decl;
   tree restype;
-  int old_immediate_size_expand = immediate_size_expand;
 
   current_function_returns_value = 0;  /* Assume, until we see it does.  */
   current_function_returns_null = 0;
   current_function_returns_abnormally = 0;
   warn_about_return_type = 0;
   current_extern_inline = 0;
-  c_in_iteration_stmt = 0;
-  c_in_case_stmt = 0;
+  c_switch_stack = NULL;
 
-  /* Don't expand any sizes in the return type of the function.  */
-  immediate_size_expand = 0;
+  /* Indicate no valid break/continue context by setting these variables
+     to some non-null, non-label value.  We'll notice and emit the proper
+     error message in c_finish_bc_stmt.  */
+  c_break_label = c_cont_label = size_zero_node;
 
   decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, NULL);
 
   /* If the declarator is not suitable for a function definition,
      cause a syntax error.  */
   if (decl1 == 0)
-    {
-      immediate_size_expand = old_immediate_size_expand;
-      return 0;
-    }
+    return 0;
 
   decl_attributes (&decl1, attributes, 0);
 
@@ -5763,14 +5847,12 @@ start_function (tree declspecs, tree declarator, tree attributes)
   push_scope ();
   declare_parm_level ();
 
-  make_decl_rtl (current_function_decl, NULL);
-
   restype = TREE_TYPE (TREE_TYPE (current_function_decl));
   /* Promote the value to int before returning it.  */
   if (c_promoting_integer_type_p (restype))
     {
       /* It retains unsignedness if not really getting wider.  */
-      if (TREE_UNSIGNED (restype)
+      if (TYPE_UNSIGNED (restype)
          && (TYPE_PRECISION (restype)
                  == TYPE_PRECISION (integer_type_node)))
        restype = unsigned_type_node;
@@ -5780,13 +5862,6 @@ start_function (tree declspecs, tree declarator, tree attributes)
   DECL_RESULT (current_function_decl)
     = build_decl (RESULT_DECL, NULL_TREE, restype);
 
-  /* If this fcn was already referenced via a block-scope `extern' decl
-     (or an implicit decl), propagate certain information about the usage.  */
-  if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl)))
-    TREE_ADDRESSABLE (current_function_decl) = 1;
-
-  immediate_size_expand = old_immediate_size_expand;
-
   start_fname_decls ();
 
   return 1;
@@ -5817,8 +5892,7 @@ store_parm_decls_newstyle (tree fndecl, tree arg_info)
      warning if we got here because ARG_INFO_TYPES was error_mark_node
      (this happens when a function definition has just an ellipsis in
      its parameter list).  */
-  else if (warn_traditional && !in_system_header
-          && DECL_CONTEXT (fndecl) == current_file_decl
+  else if (warn_traditional && !in_system_header && !current_function_scope
           && ARG_INFO_TYPES (arg_info) != error_mark_node)
     warning ("%Jtraditional C rejects ISO C style function definitions",
             fndecl);
@@ -5829,7 +5903,8 @@ store_parm_decls_newstyle (tree fndecl, tree arg_info)
     {
       DECL_CONTEXT (decl) = current_function_decl;
       if (DECL_NAME (decl))
-       bind (DECL_NAME (decl), decl, current_scope);
+       bind (DECL_NAME (decl), decl, current_scope,
+             /*invisible=*/false, /*nested=*/false);
       else
        error ("%Jparameter name omitted", decl);
     }
@@ -5842,13 +5917,15 @@ store_parm_decls_newstyle (tree fndecl, tree arg_info)
     {
       DECL_CONTEXT (decl) = current_function_decl;
       if (DECL_NAME (decl))
-       bind (DECL_NAME (decl), decl, current_scope);
+       bind (DECL_NAME (decl), decl, current_scope,
+             /*invisible=*/false, /*nested=*/false);
     }
 
   /* And all the tag declarations.  */
   for (decl = tags; decl; decl = TREE_CHAIN (decl))
     if (TREE_PURPOSE (decl))
-      bind (TREE_PURPOSE (decl), TREE_VALUE (decl), current_scope);
+      bind (TREE_PURPOSE (decl), TREE_VALUE (decl), current_scope,
+           /*invisible=*/false, /*nested=*/false);
 }
 
 /* Subroutine of store_parm_decls which handles old-style function
@@ -5884,7 +5961,7 @@ store_parm_decls_oldstyle (tree fndecl, tree arg_info)
        }
 
       b = I_SYMBOL_BINDING (TREE_VALUE (parm));
-      if (b && b->contour == current_scope)
+      if (b && B_IN_CURRENT_SCOPE (b))
        {
          decl = b->decl;
          /* If we got something other than a PARM_DECL it is an error.  */
@@ -6002,8 +6079,7 @@ store_parm_decls_oldstyle (tree fndecl, tree arg_info)
             declared for the arg.  ISO C says we take the unqualified
             type for parameters declared with qualified type.  */
          if (! comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm)),
-                          TYPE_MAIN_VARIANT (TREE_VALUE (type)),
-                          COMPARE_STRICT))
+                          TYPE_MAIN_VARIANT (TREE_VALUE (type))))
            {
              if (TYPE_MAIN_VARIANT (TREE_TYPE (parm))
                  == TYPE_MAIN_VARIANT (TREE_VALUE (type)))
@@ -6087,9 +6163,6 @@ store_parm_decls (void)
 {
   tree fndecl = current_function_decl;
 
-  /* The function containing FNDECL, if any.  */
-  tree context = decl_function_context (fndecl);
-
   /* The argument information block for FNDECL.  */
   tree arg_info = DECL_ARGUMENTS (fndecl);
 
@@ -6118,34 +6191,50 @@ store_parm_decls (void)
   allocate_struct_function (fndecl);
 
   /* Begin the statement tree for this function.  */
-  begin_stmt_tree (&DECL_SAVED_TREE (fndecl));
+  DECL_SAVED_TREE (fndecl) = push_stmt_list ();
 
-  /* If this is a nested function, save away the sizes of any
-     variable-size types so that we can expand them when generating
-     RTL.  */
-  if (context)
-    {
-      tree t;
-
-      DECL_LANG_SPECIFIC (fndecl)->pending_sizes
-       = nreverse (get_pending_sizes ());
-      for (t = DECL_LANG_SPECIFIC (fndecl)->pending_sizes;
-          t;
-          t = TREE_CHAIN (t))
-       SAVE_EXPR_CONTEXT (TREE_VALUE (t)) = context;
-    }
-
-  /* This function is being processed in whole-function mode.  */
-  cfun->x_whole_function_mode_p = 1;
+  /* ??? Insert the contents of the pending sizes list into the function
+     to be evaluated.  This just changes mis-behaviour until assign_parms
+     phase ordering problems are resolved.  */
+  {
+    tree t;
+    for (t = nreverse (get_pending_sizes ()); t ; t = TREE_CHAIN (t))
+      add_stmt (TREE_VALUE (t));
+  }
 
   /* Even though we're inside a function body, we still don't want to
      call expand_expr to calculate the size of a variable-sized array.
      We haven't necessarily assigned RTL to all variables yet, so it's
      not safe to try to expand expressions involving them.  */
-  immediate_size_expand = 0;
   cfun->x_dont_save_pending_sizes_p = 1;
 }
 \f
+/* Give FNDECL and all its nested functions to cgraph for compilation.  */
+
+static void
+c_finalize (tree fndecl)
+{
+  struct cgraph_node *cgn;
+
+  /* Handle attribute((warn_unused_result)).  Relies on gimple input.  */
+  c_warn_unused_result (&DECL_SAVED_TREE (fndecl));
+
+  /* ??? Objc emits functions after finalizing the compilation unit.
+     This should be cleaned up later and this conditional removed.  */
+  if (cgraph_global_info_ready)
+    {
+      c_expand_body (fndecl);
+      return;
+    }
+
+  /* Finalize all nested functions now.  */
+  cgn = cgraph_node (fndecl);
+  for (cgn = cgn->nested; cgn ; cgn = cgn->next_nested)
+    c_finalize (cgn->decl);
+
+  cgraph_finalize_function (fndecl, false);
+}
+
 /* Finish up a function declaration and compile that function
    all the way to assembler language output.  The free the storage
    for the function definition.
@@ -6157,22 +6246,6 @@ finish_function (void)
 {
   tree fndecl = current_function_decl;
 
-  /* When a function declaration is totally empty, e.g.
-        void foo(void) { }
-     (the argument list is irrelevant) the compstmt rule will not
-     bother calling push_scope/pop_scope, which means we get here with
-     the scope stack out of sync.  Detect this situation by noticing
-     that current_scope is still as store_parm_decls left it, and do
-     a dummy push/pop to get back to consistency.
-     Note that the call to push_scope does not actually push another
-     scope - see there for details.  */
-
-  if (current_scope->parm_flag && next_is_function_body)
-    {
-      push_scope ();
-      pop_scope ();
-    }
-
   if (TREE_CODE (fndecl) == FUNCTION_DECL
       && targetm.calls.promote_prototypes (TREE_TYPE (fndecl)))
     {
@@ -6206,20 +6279,15 @@ finish_function (void)
        }
       else
        {
-#ifdef DEFAULT_MAIN_RETURN
-         /* Make it so that `main' always returns success by default.  */
-         DEFAULT_MAIN_RETURN;
-#else
          if (flag_isoc99)
-           c_expand_return (integer_zero_node);
-#endif
+           c_finish_return (integer_zero_node);
        }
     }
 
-  finish_fname_decls ();
-
   /* Tie off the statement tree for this function.  */
-  finish_stmt_tree (&DECL_SAVED_TREE (fndecl));
+  DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
+
+  finish_fname_decls ();
 
   /* Complain if there's just no return statement.  */
   if (warn_return_type
@@ -6243,70 +6311,67 @@ finish_function (void)
       && current_function_returns_null)
     warning ("this function may return with or without a value");
 
-  /* We're leaving the context of this function, so zap cfun.
-     It's still in DECL_STRUCT_FUNCTION , and we'll restore it in
-     tree_rest_of_compilation.  */
-  cfun = NULL;
-
-  /* ??? Objc emits functions after finalizing the compilation unit.
-     This should be cleaned up later and this conditional removed.  */
-  if (!cgraph_global_info_ready)
-    cgraph_finalize_function (fndecl, false);
-  else
-    c_expand_body (fndecl);
-  current_function_decl = NULL;
-}
-
-/* Generate the RTL for the body of FNDECL.  If NESTED_P is nonzero,
-   then we are already in the process of generating RTL for another
-   function.  */
-
-static void
-c_expand_body_1 (tree fndecl, int nested_p)
-{
-  if (nested_p)
-    {
-      /* Make sure that we will evaluate variable-sized types involved
-        in our function's type.  */
-      expand_pending_sizes (DECL_LANG_SPECIFIC (fndecl)->pending_sizes);
+  /* Store the end of the function, so that we get good line number
+     info for the epilogue.  */
+  cfun->function_end_locus = input_location;
 
-      /* Squirrel away our current state.  */
-      push_function_context ();
-    }
-    
-  tree_rest_of_compilation (fndecl, nested_p);
+  /* If we don't have ctors/dtors sections, and this is a static
+     constructor or destructor, it must be recorded now.  */
+  if (DECL_STATIC_CONSTRUCTOR (fndecl)
+      && !targetm.have_ctors_dtors)
+    static_ctors = tree_cons (NULL_TREE, fndecl, static_ctors);
+  if (DECL_STATIC_DESTRUCTOR (fndecl)
+      && !targetm.have_ctors_dtors)
+    static_dtors = tree_cons (NULL_TREE, fndecl, static_dtors);
 
-  if (nested_p)
-    /* Return to the enclosing function.  */
-    pop_function_context ();
+  /* Genericize before inlining.  Delay genericizing nested functions
+     until their parent function is genericized.  Since finalizing
+     requires GENERIC, delay that as well.  */
 
-  if (DECL_STATIC_CONSTRUCTOR (fndecl))
+  if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node)
     {
-      if (targetm.have_ctors_dtors)
-       targetm.asm_out.constructor (XEXP (DECL_RTL (fndecl), 0),
-                                    DEFAULT_INIT_PRIORITY);
+      if (!decl_function_context (fndecl))
+        {
+          c_genericize (fndecl);
+         lower_nested_functions (fndecl);
+          c_finalize (fndecl);
+        }
       else
-       static_ctors = tree_cons (NULL_TREE, fndecl, static_ctors);
+        {
+          /* Register this function with cgraph just far enough to get it
+            added to our parent's nested function list.  Handy, since the
+            C front end doesn't have such a list.  */
+          (void) cgraph_node (fndecl);
+        }
     }
 
-  if (DECL_STATIC_DESTRUCTOR (fndecl))
-    {
-      if (targetm.have_ctors_dtors)
-       targetm.asm_out.destructor (XEXP (DECL_RTL (fndecl), 0),
-                                   DEFAULT_INIT_PRIORITY);
-      else
-       static_dtors = tree_cons (NULL_TREE, fndecl, static_dtors);
-    }
+  /* We're leaving the context of this function, so zap cfun.
+     It's still in DECL_STRUCT_FUNCTION, and we'll restore it in
+     tree_rest_of_compilation.  */
+  cfun = NULL;
+  current_function_decl = NULL;
 }
 
-/* Like c_expand_body_1 but only for unnested functions.  */
+/* Generate the RTL for the body of FNDECL.  */
 
 void
 c_expand_body (tree fndecl)
 {
 
-  if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node)
-    c_expand_body_1 (fndecl, 0);
+  if (!DECL_INITIAL (fndecl)
+      || DECL_INITIAL (fndecl) == error_mark_node)
+    return;
+
+  tree_rest_of_compilation (fndecl, false);
+
+  if (DECL_STATIC_CONSTRUCTOR (fndecl)
+      && targetm.have_ctors_dtors)
+    targetm.asm_out.constructor (XEXP (DECL_RTL (fndecl), 0),
+                                 DEFAULT_INIT_PRIORITY);
+  if (DECL_STATIC_DESTRUCTOR (fndecl)
+      && targetm.have_ctors_dtors)
+    targetm.asm_out.destructor (XEXP (DECL_RTL (fndecl), 0),
+                                DEFAULT_INIT_PRIORITY);
 }
 \f
 /* Check the declarations given in a for-loop for satisfying the C99
@@ -6384,9 +6449,9 @@ c_push_function_context (struct function *f)
   f->language = p;
 
   p->base.x_stmt_tree = c_stmt_tree;
-  p->base.x_scope_stmt_stack = c_scope_stmt_stack;
-  p->x_in_iteration_stmt = c_in_iteration_stmt;
-  p->x_in_case_stmt = c_in_case_stmt;
+  p->x_break_label = c_break_label;
+  p->x_cont_label = c_cont_label;
+  p->x_switch_stack = c_switch_stack;
   p->returns_value = current_function_returns_value;
   p->returns_null = current_function_returns_null;
   p->returns_abnormally = current_function_returns_abnormally;
@@ -6412,9 +6477,9 @@ c_pop_function_context (struct function *f)
     }
 
   c_stmt_tree = p->base.x_stmt_tree;
-  c_scope_stmt_stack = p->base.x_scope_stmt_stack;
-  c_in_iteration_stmt = p->x_in_iteration_stmt;
-  c_in_case_stmt = p->x_in_case_stmt;
+  c_break_label = p->x_break_label;
+  c_cont_label = p->x_cont_label;
+  c_switch_stack = p->x_switch_stack;
   current_function_returns_value = p->returns_value;
   current_function_returns_null = p->returns_null;
   current_function_returns_abnormally = p->returns_abnormally;
@@ -6464,14 +6529,6 @@ current_stmt_tree (void)
   return &c_stmt_tree;
 }
 
-/* Returns the stack of SCOPE_STMTs for the current function.  */
-
-tree *
-current_scope_stmt_stack (void)
-{
-  return &c_scope_stmt_stack;
-}
-
 /* Nonzero if TYPE is an anonymous union or struct type.  Always 0 in
    C.  */
 
@@ -6488,35 +6545,6 @@ extract_interface_info (void)
 {
 }
 
-/* Return a new COMPOUND_STMT, after adding it to the current
-   statement tree.  */
-
-tree
-c_begin_compound_stmt (void)
-{
-  tree stmt;
-
-  /* Create the COMPOUND_STMT.  */
-  stmt = add_stmt (build_stmt (COMPOUND_STMT, NULL_TREE));
-
-  return stmt;
-}
-
-/* Expand T (a DECL_STMT) if it declares an entity not handled by the
-   common code.  */
-
-void
-c_expand_decl_stmt (tree t)
-{
-  tree decl = DECL_STMT_DECL (t);
-
-  /* Expand nested functions.  */
-  if (TREE_CODE (decl) == FUNCTION_DECL
-      && DECL_CONTEXT (decl) == current_function_decl
-      && DECL_SAVED_TREE (decl))
-    c_expand_body_1 (decl, 1);
-}
-
 /* Return the global value of T as a symbol.  */
 
 tree
@@ -6525,7 +6553,7 @@ identifier_global_value   (tree t)
   struct c_binding *b;
 
   for (b = I_SYMBOL_BINDING (t); b; b = b->shadowed)
-    if (b->contour == file_scope || b->contour == external_scope)
+    if (B_IN_FILE_SCOPE (b) || B_IN_EXTERNAL_SCOPE (b))
       return b->decl;
 
   return 0;
@@ -6573,23 +6601,26 @@ make_pointer_declarator (tree type_quals_attrs, tree target)
   return build1 (INDIRECT_REF, quals, itarget);
 }
 
-/* A wrapper around lhd_set_decl_assembler_name that gives static
-   variables their C names if they are at file scope and only one
-   translation unit is being compiled, for backwards compatibility
-   with certain bizarre assembler hacks (like crtstuff.c).  */
-
-void
-c_static_assembler_name (tree decl)
+/* Synthesize a function which calls all the global ctors or global
+   dtors in this file.  This is only used for targets which do not
+   support .ctors/.dtors sections.  FIXME: Migrate into cgraph.  */
+static void
+build_cdtor (int method_type, tree cdtors)
 {
-  if (num_in_fnames == 1
-      && !TREE_PUBLIC (decl) && DECL_CONTEXT (decl)
-      && TREE_CODE (DECL_CONTEXT (decl)) == TRANSLATION_UNIT_DECL)
-    SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl));
-  else
-    lhd_set_decl_assembler_name (decl);
+  tree body = 0;
+
+  if (!cdtors)
+    return;
+
+  for (; cdtors; cdtors = TREE_CHAIN (cdtors))
+    append_to_statement_list (build_function_call (TREE_VALUE (cdtors), 0),
+                             &body);
+
+  cgraph_build_static_cdtor (method_type, body, DEFAULT_INIT_PRIORITY);
 }
 
-/* Perform final processing on file-scope data.  */
+/* Perform final processing on one file scope's declarations (or the
+   external scope's declarations), GLOBALS.  */
 static void
 c_write_global_declarations_1 (tree globals)
 {
@@ -6597,34 +6628,57 @@ c_write_global_declarations_1 (tree globals)
   tree *vec = xmalloc (sizeof (tree) * len);
   size_t i;
   tree decl;
-  
+
   /* Process the decls in the order they were written.  */
   for (i = 0, decl = globals; i < len; i++, decl = TREE_CHAIN (decl))
     vec[i] = decl;
 
   wrapup_global_declarations (vec, len);
   check_global_declarations (vec, len);
-      
+
   free (vec);
 }
 
 void
 c_write_global_declarations (void)
 {
-  tree t;
+  tree ext_block, t;
 
   /* We don't want to do this if generating a PCH.  */
   if (pch_file)
     return;
 
-  /* Process all file scopes in this compilation.  */
-  for (t = current_file_decl; t; t = TREE_CHAIN (t))
-    c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t)));
+  /* Don't waste time on further processing if -fsyntax-only or we've
+     encountered errors.  */
+  if (flag_syntax_only || errorcount || sorrycount || cpp_errors (parse_in))
+    return;
 
-  /* Now do the same for the externals scope.  */
-  t = pop_scope ();
-  if (t)
-    c_write_global_declarations_1 (BLOCK_VARS (t));
+  /* Close the external scope.  */
+  ext_block = pop_scope ();
+  external_scope = 0;
+  if (current_scope)
+    abort ();
+
+  /* Process all file scopes in this compilation, and the external_scope,
+     through wrapup_global_declarations and check_global_declarations.  */
+  for (t = all_translation_units; t; t = TREE_CHAIN (t))
+    c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t)));
+  c_write_global_declarations_1 (BLOCK_VARS (ext_block));
+
+  /* Generate functions to call static constructors and destructors
+     for targets that do not support .ctors/.dtors sections.  These
+     functions have magic names which are detected by collect2.  */
+  build_cdtor ('I', static_ctors); static_ctors = 0;
+  build_cdtor ('D', static_dtors); static_dtors = 0;
+
+  /* We're done parsing; proceed to optimize and emit assembly.
+     FIXME: shouldn't be the front end's responsibility to call this.  */
+  cgraph_optimize ();
+
+  /* Presently this has to happen after cgraph_optimize.
+     FIXME: shouldn't be the front end's responsibility to call this.  */
+  if (flag_mudflap)
+    mudflap_finish_file ();
 }
 
 #include "gt-c-decl.h"