OSDN Git Service

2003-06-10 Andrew Haley <aph@redhat.com>
[pf3gnuchains/gcc-fork.git] / gcc / c-objc-common.c
index f5e9579..32b894b 100644 (file)
@@ -1,5 +1,5 @@
 /* Some code common to C and ObjC front ends.
-   Copyright (C) 2001 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2002 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -20,6 +20,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 
 #include "config.h"
 #include "system.h"
+#include "coretypes.h"
+#include "tm.h"
 #include "tree.h"
 #include "rtl.h"
 #include "insn-config.h"
@@ -34,6 +36,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "varray.h"
 #include "ggc.h"
 #include "langhooks.h"
+#include "target.h"
+#include "cgraph.h"
 
 static bool c_tree_printer PARAMS ((output_buffer *, text_info *));
 static tree inline_forbidden_p PARAMS ((tree *, int *, void *));
@@ -91,7 +95,7 @@ inline_forbidden_p (nodep, walk_subtrees, fn)
        {
          /* We cannot inline functions that take a variable number of
             arguments.  */
-       case BUILT_IN_VARARGS_START:
+       case BUILT_IN_VA_START:
        case BUILT_IN_STDARG_START:
 #if 0
          /* Functions that need information about the address of the
@@ -120,7 +124,7 @@ inline_forbidden_p (nodep, walk_subtrees, fn)
       /* We will not inline a function which uses computed goto.  The
         addresses of its local labels, which may be tucked into
         global storage, are of course not constant across
-        instantiations, which causes unexpected behaviour.  */
+        instantiations, which causes unexpected behavior.  */
       if (TREE_CODE (t) != LABEL_DECL)
        return node;
 
@@ -132,6 +136,22 @@ inline_forbidden_p (nodep, walk_subtrees, fn)
 
       break;
 
+    case RECORD_TYPE:
+    case UNION_TYPE:
+      /* We cannot inline a function of the form
+
+          void F (int i) { struct S { int ar[i]; } s; }
+
+        Attempting to do so produces a catch-22 in tree-inline.c.
+        If walk_tree examines the TYPE_FIELDS chain of RECORD_TYPE/
+        UNION_TYPE nodes, then it goes into infinite recursion on a
+        structure containing a pointer to its own type.  If it doesn't,
+        then the type node for S doesn't get adjusted properly when
+        F is inlined, and we abort in find_function_data.  */
+      for (t = TYPE_FIELDS (node); t; t = TREE_CHAIN (t))
+       if (variably_modified_type_p (TREE_TYPE (t)))
+         return node;
+
     default:
       break;
     }
@@ -150,11 +170,13 @@ c_cannot_inline_tree_fn (fnp)
       && lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn)) == NULL)
     return 1;
 
+  /* Don't auto-inline anything that might not be bound within 
+     this unit of translation.  */
+  if (!DECL_DECLARED_INLINE_P (fn) && !(*targetm.binds_local_p) (fn))
+    goto cannot_inline;
+
   if (! function_attribute_inlinable_p (fn))
-    {
-      DECL_UNINLINABLE (fn) = 1;
-      return 1;
-    }
+    goto cannot_inline;
 
   /* If a function has pending sizes, we must not defer its
      compilation, and we can't inline it as a tree.  */
@@ -164,10 +186,7 @@ c_cannot_inline_tree_fn (fnp)
       put_pending_sizes (t);
 
       if (t)
-       {
-         DECL_UNINLINABLE (fn) = 1;
-         return 1;
-       }
+       goto cannot_inline;
     }
 
   if (DECL_CONTEXT (fn))
@@ -175,10 +194,7 @@ c_cannot_inline_tree_fn (fnp)
       /* If a nested function has pending sizes, we may have already
          saved them.  */
       if (DECL_LANG_SPECIFIC (fn)->pending_sizes)
-       {
-         DECL_UNINLINABLE (fn) = 1;
-         return 1;
-       }
+       goto cannot_inline;
     }
   else
     {
@@ -201,12 +217,13 @@ c_cannot_inline_tree_fn (fnp)
     }
     
   if (walk_tree (&DECL_SAVED_TREE (fn), inline_forbidden_p, fn, NULL))
-    {
-      DECL_UNINLINABLE (fn) = 1;
-      return 1;
-    }
+    goto cannot_inline;
 
   return 0;
+
+ cannot_inline:
+  DECL_UNINLINABLE (fn) = 1;
+  return 1;
 }
 
 /* Called from check_global_declarations.  */
@@ -224,15 +241,19 @@ c_warn_unused_global_decl (decl)
 }
 
 /* Initialization common to C and Objective-C front ends.  */
-const char *
-c_objc_common_init (filename)
-     const char *filename;
+bool
+c_objc_common_init ()
 {
+  static const enum tree_code stmt_codes[] = {
+    c_common_stmt_codes
+  };
+
+  INIT_STATEMENT_CODES (stmt_codes);
+
   c_init_decl_processing ();
 
-  filename = c_common_init (filename);
-  if (filename == NULL)
-    return NULL;
+  if (c_common_init () == false)
+    return false;
 
   lang_expand_decl_stmt = c_expand_decl_stmt;
 
@@ -254,7 +275,7 @@ c_objc_common_init (filename)
 
   VARRAY_TREE_INIT (deferred_fns, 32, "deferred_fns");
 
-  return filename;
+  return true;
 }
 
 /* Register a function tree, so that its optimization and conversion
@@ -342,7 +363,16 @@ finish_cdtor (body)
 void
 c_objc_common_finish_file ()
 {
-  expand_deferred_fns ();
+  if (pch_file)
+    c_common_write_pch ();
+
+  if (flag_unit_at_a_time)
+    {
+      cgraph_finalize_compilation_unit ();
+      cgraph_optimize ();
+    }
+  else
+    expand_deferred_fns ();
 
   if (static_ctors)
     {