[llvm-commits] [llvm-gcc-4.2] r58599 - in /llvm-gcc-4.2/trunk/gcc: attribs.c c-common.c c-common.h c-decl.c c-parser.c c-typeck.c config/darwin-c.c config/darwin-sections.def config/darwin.c config/darwin.h config/i386/i386.c coverage.c cp/call.c cp/decl.c cp/name-lookup.c cp/parser.c cp/tree.c cp/typeck.c dwarf2out.c function.c gimplify.c ipa-type-escape.c objc/objc-act.c stub-objc.c tree-inline.c tree.c tree.h varasm.c version.c

Bill Wendling isanbard at gmail.com
Sun Nov 2 23:33:16 PST 2008


Author: void
Date: Mon Nov  3 01:33:15 2008
New Revision: 58599

URL: http://llvm.org/viewvc/llvm-project?rev=58599&view=rev
Log:
Many, many blocks updates. Sync with Apple GCC mainline.

Modified:
    llvm-gcc-4.2/trunk/gcc/attribs.c
    llvm-gcc-4.2/trunk/gcc/c-common.c
    llvm-gcc-4.2/trunk/gcc/c-common.h
    llvm-gcc-4.2/trunk/gcc/c-decl.c
    llvm-gcc-4.2/trunk/gcc/c-parser.c
    llvm-gcc-4.2/trunk/gcc/c-typeck.c
    llvm-gcc-4.2/trunk/gcc/config/darwin-c.c
    llvm-gcc-4.2/trunk/gcc/config/darwin-sections.def
    llvm-gcc-4.2/trunk/gcc/config/darwin.c
    llvm-gcc-4.2/trunk/gcc/config/darwin.h
    llvm-gcc-4.2/trunk/gcc/config/i386/i386.c
    llvm-gcc-4.2/trunk/gcc/coverage.c
    llvm-gcc-4.2/trunk/gcc/cp/call.c
    llvm-gcc-4.2/trunk/gcc/cp/decl.c
    llvm-gcc-4.2/trunk/gcc/cp/name-lookup.c
    llvm-gcc-4.2/trunk/gcc/cp/parser.c
    llvm-gcc-4.2/trunk/gcc/cp/tree.c
    llvm-gcc-4.2/trunk/gcc/cp/typeck.c
    llvm-gcc-4.2/trunk/gcc/dwarf2out.c
    llvm-gcc-4.2/trunk/gcc/function.c
    llvm-gcc-4.2/trunk/gcc/gimplify.c
    llvm-gcc-4.2/trunk/gcc/ipa-type-escape.c
    llvm-gcc-4.2/trunk/gcc/objc/objc-act.c
    llvm-gcc-4.2/trunk/gcc/stub-objc.c
    llvm-gcc-4.2/trunk/gcc/tree-inline.c
    llvm-gcc-4.2/trunk/gcc/tree.c
    llvm-gcc-4.2/trunk/gcc/tree.h
    llvm-gcc-4.2/trunk/gcc/varasm.c
    llvm-gcc-4.2/trunk/gcc/version.c

Modified: llvm-gcc-4.2/trunk/gcc/attribs.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/attribs.c?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/attribs.c (original)
+++ llvm-gcc-4.2/trunk/gcc/attribs.c Mon Nov  3 01:33:15 2008
@@ -216,7 +216,8 @@
       if (spec->function_type_required && TREE_CODE (*anode) != FUNCTION_TYPE
 	  && TREE_CODE (*anode) != METHOD_TYPE)
 	{
-	  if (TREE_CODE (*anode) == POINTER_TYPE
+	  /* APPLE LOCAL radar 6246527 */
+	  if ((TREE_CODE (*anode) == POINTER_TYPE || TREE_CODE (*anode) == BLOCK_POINTER_TYPE)
 	      && (TREE_CODE (TREE_TYPE (*anode)) == FUNCTION_TYPE
 		  || TREE_CODE (TREE_TYPE (*anode)) == METHOD_TYPE))
 	    {
@@ -323,6 +324,14 @@
 
       if (fn_ptr_tmp)
 	{
+          /* APPLE LOCAL begin radar 6246527 */
+          if (DECL_P (*node) && TREE_TYPE (*node) && 
+              TREE_CODE (TREE_TYPE (*node)) == BLOCK_POINTER_TYPE)
+            /* Rebuild the block pointer type and put it in the
+               appropriate place.  */
+            fn_ptr_tmp = build_block_pointer_type (fn_ptr_tmp);
+          else
+          /* APPLE LOCAL end radar 6246527 */
 	  /* Rebuild the function pointer type and put it in the
 	     appropriate place.  */
 	  fn_ptr_tmp = build_pointer_type (fn_ptr_tmp);

Modified: llvm-gcc-4.2/trunk/gcc/c-common.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/c-common.c?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/c-common.c (original)
+++ llvm-gcc-4.2/trunk/gcc/c-common.c Mon Nov  3 01:33:15 2008
@@ -201,11 +201,8 @@
 	tree saved_function_name_decls;
 
 */
-
-/* APPLE LOCAL begin radar 5811943 - Fix type of pointers to Blocks  */
-/* Move declaration of invoke_impl_ptr_type from c-typeck.c  */
-tree invoke_impl_ptr_type;
-/* APPLE LOCAL end radar 5811943 - Fix type of pointers to Blocks  */
+/* APPLE LOCAL radar 6300081  */
+tree generic_block_literal_struct_type = NULL;
 
 tree c_global_trees[CTI_MAX];
 
@@ -302,7 +299,8 @@
 /* Warn about format/argument anomalies in calls to formatted I/O functions
    (*printf, *scanf, strftime, strfmon, etc.).  */
 
-int warn_format;
+/* APPLE LOCAL default to Wformat-security 5764921 */
+int warn_format = 1;
 
 /* Warn about using __null (as NULL in C++) as sentinel.  For code compiled
    with GCC this doesn't matter as __null is guaranteed to have the right
@@ -6130,7 +6128,7 @@
   *no_add_attrs = true;
   if (!(*node) || TREE_CODE (*node) != VAR_DECL)
     {
-      warning (OPT_Wattributes, "byref attribute can be specified on variables only - ignored");
+      warning (OPT_Wattributes, "__block attribute can be specified on variables only - ignored");
       return NULL_TREE;
     }
   arg_ident = TREE_VALUE (args);
@@ -6242,7 +6240,7 @@
 }
 
 /* This routine builds call to:
- _Block_byref_release(VAR_DECL.forwarding);
+ _Block_byref_release(VAR_DECL.__forwarding);
  and adds it to the statement list.
  */
 tree
@@ -6250,9 +6248,9 @@
 {
   tree exp = var_decl, call_exp, func_params;
   tree type = TREE_TYPE (var_decl);
-  /* __byref variables imported into Blocks are not _Block_byref_released()
+  /* __block variables imported into Blocks are not _Block_byref_released()
    from within the Block statement itself; otherwise, each envokation of
-   the block causes a release. Make sure to release __byref variables declared 
+   the block causes a release. Make sure to release __block variables declared 
    and used locally in the block though. */
   if (cur_block 
       && (BLOCK_DECL_COPIED (var_decl) || BLOCK_DECL_BYREF (var_decl)))
@@ -6266,7 +6264,7 @@
   TREE_USED (var_decl) = 1;
 
   /* Declare: _Block_byref_release(void*) if not done already. */
-  exp = build_component_ref (exp, get_identifier ("forwarding"));
+  exp = build_component_ref (exp, get_identifier ("__forwarding"));
   func_params = tree_cons (NULL_TREE, exp, NULL_TREE);
   call_exp = build_function_call (build_block_byref_release_decl (), func_params);
   return call_exp;
@@ -9141,5 +9139,55 @@
     warning (OPT_Wchar_subscripts, "array subscript has type %<char%>");
 }
 
+/* APPLE LOCAL begin radar 6246527 */
+/* This routine is called for a "format" attribute. It adds the number of
+ hidden argument ('1') to the format's 2nd and 3rd argument to compensate
+ for these two arguments. This is to make rest of the "format" attribute
+ processing done in the middle-end to work seemlessly. */
+
+static void
+block_delta_format_args (tree format)
+{
+  tree format_num_expr, first_arg_num_expr;
+  int val; 
+  tree args = TREE_VALUE (format);
+  gcc_assert (TREE_CHAIN (args) && TREE_CHAIN (TREE_CHAIN (args)));
+  format_num_expr = TREE_VALUE (TREE_CHAIN (args));
+  first_arg_num_expr = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args)));
+  if (format_num_expr && TREE_CODE (format_num_expr) == INTEGER_CST)
+  {
+    val = TREE_INT_CST_LOW (format_num_expr);
+    TREE_VALUE (TREE_CHAIN (args)) = build_int_cst (NULL_TREE, val+1);
+  }
+  if (first_arg_num_expr && TREE_CODE (first_arg_num_expr) == INTEGER_CST)
+  {
+    val = TREE_INT_CST_LOW (first_arg_num_expr);
+    if (val != 0)
+      TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args))) = 
+                                              build_int_cst (NULL_TREE, val+1);
+  }
+}
+
+/* This routine recognizes legal block attributes. In case of block's "format" 
+ attribute, it calls block_delta_format_args to compensate for hidden 
+ argument _self getting passed to block's helper function. */
+bool
+any_recognized_block_attribute (tree attributes)
+{
+  tree chain;
+  bool res = false;
+  for (chain = attributes; chain; chain = TREE_CHAIN (chain))
+  {
+    if (is_attribute_p ("format", TREE_PURPOSE (chain)))
+    {
+      block_delta_format_args (chain);
+      res = true;
+    }
+    else if (is_attribute_p ("sentinel", TREE_PURPOSE (chain)))
+      res = true;	
+  }
+  return res;
+}
+/* APPLE LOCAL end radar 6246527 */
 
 #include "gt-c-common.h"

Modified: llvm-gcc-4.2/trunk/gcc/c-common.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/c-common.h?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/c-common.h (original)
+++ llvm-gcc-4.2/trunk/gcc/c-common.h Mon Nov  3 01:33:15 2008
@@ -978,9 +978,10 @@
 extern tree objc_non_volatilized_type (tree);
 /* APPLE LOCAL radar 4697411 */
 extern void objc_volatilize_component_ref (tree, tree);
-extern bool objc_compare_types (tree, tree, int, tree);
-/* APPLE LOCAL radar 4229905 */
-extern bool objc_have_common_type (tree, tree, int, tree);
+/* APPLE LOCAL radar 6231433 */
+extern bool objc_compare_types (tree, tree, int, tree, const char *);
+/* APPLE LOCAL radar 4229905 - radar 6231433 */
+extern bool objc_have_common_type (tree, tree, int, tree, const char *);
 /* APPLE LOCAL radar 4133425 */
 extern bool objc_diagnose_private_ivar (tree);
 /* APPLE LOCAL radar 4507230 */
@@ -1127,7 +1128,9 @@
      BLOCK_HAS_CXX_OBJ =       (1 << 26), 
      BLOCK_IS_GC =             (1 << 27),
      /* APPLE LOCAL radar 5822844 */
-     BLOCK_IS_GLOBAL = 	       (1 << 28)
+     BLOCK_IS_GLOBAL = 	       (1 << 28),
+     /* APPLE LOCAL radar 5847213 */
+     BLOCK_HAS_DESCRIPTOR =    (1 << 29)
 };
 
 struct block_sema_info {
@@ -1142,7 +1145,7 @@
   /* APPLE LOCAL radar 5803600 */
   tree block_byref_global_decl_list;
   tree block_original_ref_decl_list;
-  tree block_original_byref_decl_list;
+  /* APPLE LOCAL radar 5847213 - tree block_original_byref_decl_list is removed. */
   tree block_body;
   bool hasPrototype;
   bool isVariadic;
@@ -1169,17 +1172,12 @@
 
 extern struct block_sema_info *cur_block;
 extern tree build_helper_func_decl (tree, tree);
-extern bool building_block_byref_decl;
-/* APPLE LOCAL - begin radar 6113240 */
-/* Move invoke_impl_ptr_type to tree.h */
-/* APPLE LOCAL - end radar 6113240 */
 extern tree build_block_byref_decl (tree, tree, tree);
 extern tree build_block_ref_decl (tree, tree);
 extern tree begin_block (void);
 extern struct block_sema_info *finish_block (tree);
 extern bool in_imm_block (void);
 extern bool lookup_name_in_block (tree, tree*);
-extern void build_block_internal_types (void);
 extern void push_to_top_level (void);
 extern void pop_from_top_level (void);
 extern void start_block_helper_function (tree func_decl);
@@ -1199,17 +1197,17 @@
 extern tree do_digest_init (tree, tree);
 extern tree cast_to_pointer_to_id (tree);
 /* APPLE LOCAL end radar 5932809 - copyable byref blocks */
-
+/* APPLE LOCAL begin radar 6237713 */
+extern bool any_recognized_block_attribute (tree);
+/* APPLE LOCAL end radar 6237713 */
+
+/* APPLE LOCAL begin radar 5847213 */
+extern tree build_block_descriptor_type (bool);
+/* APPLE LOCAL end radar 5847213 */
 /* APPLE LOCAL begin radar 6083129 - byref escapes */
-extern void gen_block_byref_release_exp (tree);
 extern tree build_block_byref_release_exp (tree);
 extern tree build_block_byref_release_decl (void);
 extern tree build_block_byref_assign_copy_decl (void);
-extern void release_all_local_byrefs_at_return (void);
-void diagnose_byref_var_in_current_scope (void);
-extern void release_local_byrefs_at_break (void);
-extern void in_bc_stmt_block (void);
-extern void outof_bc_stmt_block (void);
 /* APPLE LOCAL end radar 6083129 - byref escapes */
 
 /* APPLE LOCAL radar 6040305 - blocks */

Modified: llvm-gcc-4.2/trunk/gcc/c-decl.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/c-decl.c?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/c-decl.c (original)
+++ llvm-gcc-4.2/trunk/gcc/c-decl.c Mon Nov  3 01:33:15 2008
@@ -326,14 +326,6 @@
   tree blocks;
   tree blocks_last;
 
-  /* APPLE LOCAL begin radar 6083129 -  byref escapes (C++ cp) */
-  /* Non-zero if outermost block of a statement which can have a 
-     break/continue stmt; such as while, switch, etc. This cannot be
-     a boolen field because the same scope can be used for a nested
-     while/for statement; as in, while(...) while (...). */
-  unsigned int  bc_stmt_body;
-  /* APPLE LOCAL end radar 6083129 -  byref escapes (C++ cp) */
-
   /* The depth of this scope.  Used to keep the ->shadowed chain of
      bindings sorted innermost to outermost.  */
   unsigned int depth : 28;
@@ -359,12 +351,6 @@
 
   /* True means make a BLOCK for this scope no matter what.  */
   BOOL_BITFIELD keep : 1;
-
-  /* APPLE LOCAL begin radar 6083129 -  byref escapes (C++ cp) */
-  /* When true, current scope has at least one local __byref variable
-     in its scope. This flag is used for compile-time performance.  */
-  BOOL_BITFIELD byref_in_current_scope : 1;
-  /* APPLE LOCAL end radar 6083129 -  byref escapes (C++ cp) */
 };
 
 /* The scope currently in effect.  */
@@ -688,10 +674,6 @@
       scope->keep          = keep_next_level_flag;
       scope->outer         = current_scope;
       scope->depth	   = current_scope ? (current_scope->depth + 1) : 0;
-      /* APPLE LOCAL begin radar 6083129 -  byref escapes (C++ cp) */
-      scope->byref_in_current_scope = 
-        current_scope ? current_scope->byref_in_current_scope : false;
-      /* APPLE LOCAL end radar 6083129 -  byref escapes (C++ cp) */
 
       /* Check for scope depth overflow.  Unlikely (2^28 == 268,435,456) but
 	 possible.  */
@@ -716,111 +698,6 @@
     TYPE_CONTEXT (type) = context;
 }
 
-/* APPLE LOCAL begin radar 6083129 -  byref escapes (C++ cp) */
-/* This routine is called at the begining of parsing of a while/for, etc.
-   statement and sets bc_stmt_body in current scope to say that outer scope
-   is for such a statement. */
-void
-in_bc_stmt_block (void)
-{
-  gcc_assert (current_scope);
-  ++current_scope->bc_stmt_body;
-}
-
-/*  This routine resets the bc_stmt_body flag before exiting the top-most
-    block of while/for, etc. statement. */
-void
-outof_bc_stmt_block (void)
-{
-  gcc_assert (current_scope && current_scope->bc_stmt_body > 0);
-  --current_scope->bc_stmt_body;
-}
-
-/* This routine generates calls of _Block_byref_release(VAR_DECL.forwarding);
-   for all byref variables seen in the scope of the return statement.
-*/
-void
-release_all_local_byrefs_at_return (void)
-{
-  struct c_scope *scope;
-  struct c_binding *b;
-
-  gcc_assert (current_scope);
-  if (flag_objc_gc_only || !current_scope->byref_in_current_scope)
-    return;
-
-  scope = current_scope;
-  while (scope && scope != file_scope)
-  {
-    for (b = scope->bindings; b; b = b->prev)
-    {
-      tree p = b->decl;
-      if (p && TREE_CODE (p) == VAR_DECL && COPYABLE_BYREF_LOCAL_VAR (p))
-	gen_block_byref_release_exp (p);
-    }
-    /* Release up to scope of the block. */
-    if (cur_block && cur_block->the_scope == scope)
-      break;
-    scope = scope->outer;
-  }
-}
-
-/* This routine issues a diagnostic if a __byref variable is seen in
-   current scope. This is for now called from a goto statement.  */
-void
-diagnose_byref_var_in_current_scope (void)
-{
-  struct c_scope *scope;
-  struct c_binding *b;
-
-  gcc_assert (current_scope);
-  if (flag_objc_gc_only || !current_scope->byref_in_current_scope)
-    return;
-
-  scope = current_scope;
-  while (scope && scope != file_scope)
-  {
-    for (b = scope->bindings; b; b = b->prev)
-    {
-      tree p = b->decl;
-      if (p && TREE_CODE (p) == VAR_DECL && COPYABLE_BYREF_LOCAL_VAR (p)) {
-        error ("local byref variable %s is in the scope of this goto",
-               IDENTIFIER_POINTER (DECL_NAME (p)));
-        return;
-      }
-    }
-    scope = scope->outer;
-  }
-}
-
-/* This routine generates call to
-   _Block_byref_release(VAR_DECL.forwarding); for all __byref
-   variables which go out of scope when 'break' is executed.  */
-void
-release_local_byrefs_at_break (void)
-{
-  struct c_scope *scope;
-  struct c_binding *b;
-
-  gcc_assert (current_scope);
-  if (flag_objc_gc_only || !current_scope->byref_in_current_scope)
-    return;
-
-  scope = current_scope;
-  while (scope && !scope->bc_stmt_body)
-  {
-    for (b = scope->bindings; b; b = b->prev)
-    {
-      tree p = b->decl;
-      if (p && TREE_CODE (p) == VAR_DECL && COPYABLE_BYREF_LOCAL_VAR (p))
-	gen_block_byref_release_exp (p);
-    }
-    scope = scope->outer;
-  }
-}
-
-/* APPLE LOCAL end radar 6083129 -  byref escapes (C++ cp) */
-
 /* 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
@@ -951,11 +828,6 @@
 	  goto common_symbol;
 
 	case VAR_DECL:
-         /* APPLE LOCAL begin radar 6083129 -  byref escapes (C++ cp) */
-            if (!flag_objc_gc_only && COPYABLE_BYREF_LOCAL_VAR (p))
-	      gen_block_byref_release_exp (p);
-         /* APPLE LOCAL end radar 6083129 -  byref escapes (C++ cp) */
-
 	  /* Warnings for unused variables.  */
 	  if (!TREE_USED (p)
 	      && !TREE_NO_WARNING (p)
@@ -3836,12 +3708,12 @@
 
   struct __Block_byref_x {
     // APPLE LOCAL radar 6244520
-    void *isa;			// NULL for everything except __weak pointers
-    struct Block_byref_x *forwarding;
-    int32_t flags;
-    int32_t size;
-    void *ByrefKeepFuncPtr;    // Only if variable is __byref ObjC object
-    void *ByrefDestroyFuncPtr; // Only if variable is __byref ObjC object
+    void *__isa;			// NULL for everything except __weak pointers
+    struct Block_byref_x *__forwarding;
+    int32_t __flags;
+    int32_t __size;
+    void *__ByrefKeepFuncPtr;    // Only if variable is __block ObjC object
+    void *__ByrefDestroyFuncPtr; // Only if variable is __block ObjC object
     typex x;
   } x;
 */
@@ -3863,36 +3735,36 @@
   Block_byref_type = start_struct (RECORD_TYPE, get_identifier (string));
 
   /* APPLE LOCAL begin radar 6244520 */
-  /* void *isa; */
-  field_decl = build_decl (FIELD_DECL, get_identifier ("isa"), ptr_type_node);
+  /* void *__isa; */
+  field_decl = build_decl (FIELD_DECL, get_identifier ("__isa"), ptr_type_node);
   field_decl_chain = field_decl;
   /* APPLE LOCAL end radar 6244520 */
 
-  /* struct Block_byref_x *forwarding; */
-  field_decl = build_decl (FIELD_DECL, get_identifier ("forwarding"),
+  /* struct Block_byref_x *__forwarding; */
+  field_decl = build_decl (FIELD_DECL, get_identifier ("__forwarding"),
                            build_pointer_type (Block_byref_type));
   /* APPLE LOCAL radar 6244520 */
   chainon (field_decl_chain, field_decl);
 
-  /* int32_t flags; */
-  field_decl = build_decl (FIELD_DECL, get_identifier ("flags"),
+  /* int32_t __flags; */
+  field_decl = build_decl (FIELD_DECL, get_identifier ("__flags"),
                            unsigned_type_node);
   chainon (field_decl_chain, field_decl);
 
-  /* int32_t size; */
-  field_decl = build_decl (FIELD_DECL, get_identifier ("size"),
+  /* int32_t __size; */
+  field_decl = build_decl (FIELD_DECL, get_identifier ("__size"),
                            unsigned_type_node);
   chainon (field_decl_chain, field_decl);
 
   if (COPYABLE_BYREF_LOCAL_NONPOD (decl))
     {
-      /* void *ByrefKeepFuncPtr; */
-      field_decl = build_decl (FIELD_DECL, get_identifier ("ByrefKeepFuncPtr"),
+      /* void *__ByrefKeepFuncPtr; */
+      field_decl = build_decl (FIELD_DECL, get_identifier ("__ByrefKeepFuncPtr"),
 			       ptr_type_node);
       chainon (field_decl_chain, field_decl);
 
-      /* void *ByrefDestroyFuncPtr; */
-      field_decl = build_decl (FIELD_DECL, get_identifier ("ByrefDestroyFuncPtr"),
+      /* void *__ByrefDestroyFuncPtr; */
+      field_decl = build_decl (FIELD_DECL, get_identifier ("__ByrefDestroyFuncPtr"),
 			       ptr_type_node);
       chainon (field_decl_chain, field_decl);
   }
@@ -3919,7 +3791,7 @@
    { NULL, &x, 0, sizeof(struct __Block_byref_x)};
    when INIT is NULL_TREE
 
-   For __byref ObjC objects, it also adds "byref_keep" and "byref_destroy"
+   For __block ObjC objects, it also adds "byref_keep" and "byref_destroy"
    Funtion pointers. So the most general initializers would be:
 
    { NULL, &x, 0, sizeof(struct __Block_byref_x), &byref_keep, &byref_destroy,
@@ -4034,23 +3906,28 @@
   if (TREE_CODE (decl) == PARM_DECL)
     init = 0;
   /* APPLE LOCAL begin radar 5932809 - copyable byref blocks (C++ cq) */
-  /* We build a new type for each local variable declared as __byref
+  /* We build a new type for each local variable declared as __block
      and initialize it to a list of initializers. */
   else if (TREE_CODE (decl) == VAR_DECL && COPYABLE_BYREF_LOCAL_VAR (decl))
     {
       if (DECL_EXTERNAL (decl) || TREE_STATIC (decl))
 	{
 	  warning (0,
-		   "__byref attribute is only allowed on local variables - ignored");
+		   "__block attribute is only allowed on local variables - ignored");
 	  COPYABLE_BYREF_LOCAL_VAR (decl) = 0;
 	  COPYABLE_BYREF_LOCAL_NONPOD (decl) = 0;
 	}
       else
 	{
 	  decl = new_block_byref_decl (decl);
+	  /* APPLE LOCAL begin radar 6289031 */
+	  if (! flag_objc_gc_only)
+	    {
+              push_cleanup (decl, build_block_byref_release_exp (decl), false);
+	    }
+	  /* APPLE LOCAL end radar 6289031 */
+
 	  init = init_byref_decl (decl, init);
-          /* Mark that current scope has a __byref local variable. */
-          current_scope->byref_in_current_scope = true;
 	}
     }
   /* APPLE LOCAL end radar 5932809 - copyable byref blocks (C++ cq) */
@@ -7717,6 +7594,13 @@
 	  error ("%<enum %E%> declared in %<for%> loop initial declaration",
 		 id);
 	  break;
+        /* APPLE LOCAL begin radar 6268817 */
+        case FUNCTION_DECL:
+        /* Block helper function can be declared in the statement block
+           for the for-loop declarations. */
+          if (BLOCK_SYNTHESIZED_FUNC (decl))
+            break;
+        /* APPLE LOCAL end radar 6268817 */
 	default:
 	  error ("declaration of non-variable %q+D in %<for%> loop "
 		 "initial declaration", decl);
@@ -7949,12 +7833,12 @@
 
 /* APPLE LOCAL begin radar 5932809 - copyable byref blocks (C++ ch) */
 /* build_byref_local_var_access - converts EXPR to:
-   EXPR.forwarding-><decl-name>.
+   EXPR.__forwarding-><decl-name>.
 */
 tree
 build_byref_local_var_access (tree expr, tree decl_name)
 {
-  tree exp = build_component_ref (expr, get_identifier ("forwarding"));
+  tree exp = build_component_ref (expr, get_identifier ("__forwarding"));
   exp = build_indirect_ref (exp, "unary *");
   exp = build_component_ref (exp, decl_name);
   return exp;
@@ -7969,13 +7853,49 @@
 build_block_byref_decl (tree name, tree decl, tree exp)
 {
   struct c_scope *scope = current_scope;
+  tree ptr_type, byref_decl;
+  /* APPLE LOCAL begin radar 6225809 */
+  if (cur_block->prev_block_info) {
+    /* Traverse enclosing blocks. Insert a __block variable in
+     each enclosing block which has no declaration of this
+     variable. This is to ensure that the current (inner) block
+     gets the __block version of the variable; */
+    struct block_sema_info *cb = cur_block->prev_block_info;
+    while (cb) {
+      struct c_binding *b = I_SYMBOL_BINDING (name);
+      /* Find the first declaration not in current block. */
+      while (b && b->decl
+             && (TREE_CODE (b->decl) == VAR_DECL
+                 || TREE_CODE (b->decl) == PARM_DECL)
+             && b->depth >= cur_block->the_scope->depth)
+        b = b->shadowed;
+      
+      /* Is the next declaration not in enclosing block? */
+      if (b && b->decl
+          && (TREE_CODE (b->decl) == VAR_DECL
+              || TREE_CODE (b->decl) == PARM_DECL)
+          && b->depth < cb->the_scope->depth) {
+        /* No declaration of variable seen in the block. Must insert one. */
+        struct c_scope *save_scope = current_scope;
+        struct block_sema_info *save_current_block = cur_block;
+        current_scope = cb->the_scope;
+        cur_block = cb;
+        decl = build_block_byref_decl (name, decl, exp);
+        cur_block = save_current_block;
+        current_scope = save_scope;
+      }
+      cb = cb->prev_block_info;
+    }
+  }
+  /* APPLE LOCAL end radar 6225809 */
+  
   /* If it is already a byref declaration, do not add the pointer type
      because such declarations already have the pointer type
      added. This happens when we have two nested byref declarations in
      nested blocks. */
-  tree ptr_type = (TREE_CODE (decl) == VAR_DECL && BLOCK_DECL_BYREF (decl))
-                   ? TREE_TYPE (decl) : build_pointer_type (TREE_TYPE (decl));
-  tree byref_decl = build_decl (VAR_DECL, name, ptr_type);
+  ptr_type = (TREE_CODE (decl) == VAR_DECL && BLOCK_DECL_BYREF (decl))
+              ? TREE_TYPE (decl) : build_pointer_type (TREE_TYPE (decl));
+  byref_decl = build_decl (VAR_DECL, name, ptr_type);
   /* APPLE LOCAL begin radars 6144664 & 6145471  */
   DECL_SOURCE_LOCATION (byref_decl) = DECL_SOURCE_LOCATION 
                                                (cur_block->helper_func_decl);
@@ -8001,8 +7921,12 @@
         scope, /*invisible=*/false, /*nested=*/false);
   cur_block->block_byref_decl_list =
     tree_cons (NULL_TREE, byref_decl, cur_block->block_byref_decl_list);
-  cur_block->block_original_byref_decl_list =
-    tree_cons (NULL_TREE, exp, cur_block->block_original_byref_decl_list);
+  /* APPLE LOCAL radar 5847213 - building block_original_byref_decl_list list removed. */
+  /* APPLE LOCAL begin radar 6289031 */
+  if (! flag_objc_gc_only)
+    push_cleanup (byref_decl, build_block_byref_release_exp (byref_decl), false);
+  /* APPLE LOCAL end radar 6289031 */
+
   return byref_decl;
 }
 
@@ -8020,7 +7944,7 @@
   /* APPLE LOCAL radar 6212722 */
   tree type, exp;
   /* APPLE LOCAL begin radar 5932809 - copyable byref blocks (C++ ch) */
-  /* 'decl' was previously declared as __byref. Simply, copy the value
+  /* 'decl' was previously declared as __block. Simply, copy the value
      embedded in the above variable. */
   if (TREE_CODE (decl) == VAR_DECL && COPYABLE_BYREF_LOCAL_VAR (decl))
     decl = build_byref_local_var_access (decl, DECL_NAME (decl));
@@ -8106,62 +8030,68 @@
   return ref_decl;
 }
 
-/* APPLE LOCAL begin radar 5939894 (C++ ch) */
-/** build_block_internal_types - This routine builds the block type:
- struct __invoke_impl {
- void   *isa;
- int32_t Flags;
- int32_t Size;
- void *FuncPtr;
- } *invoke_impl_ptr_type;
- */
-void
-build_block_internal_types (void)
+/* APPLE LOCAL begin radar 5847213 - radar 6329245 */
+static GTY (())  tree descriptor_ptr_type;
+static GTY (())  tree descriptor_ptr_type_with_copydispose;
+/** build_block_descriptor_type - This routine builds following internal type:
+ struct __block_descriptor {
+ unsigned long int reserved;     // NULL
+ unsigned long int Size;  // sizeof(struct Block_literal_1)
+ 
+ // optional helper functions
+ void *CopyFuncPtr; // When BLOCK_HAS_COPY_DISPOSE is set (withCopyDispose true)
+ void *DestroyFuncPtr; // When BLOCK_HAS_COPY_DISPOSE is set (withCopyDispose true)
+} *descriptor_ptr_type;
+
+Objects of this type will always be static. This is one main component of abi change.
+*/
+tree
+build_block_descriptor_type (bool withCopyDispose)
 {
   tree field_decl_chain, field_decl;
-  tree invoke_impl_type;
-
-  /* APPLE LOCAL begin radar 5939894 (C++ ch) */
-  /* If a user-declaration of "struct __invoke_impl" is seen, use it. */
-  invoke_impl_type = lookup_tag (RECORD_TYPE, get_identifier ("__invoke_impl"), 0);
-  if (invoke_impl_type)
-  {
-    invoke_impl_ptr_type = build_pointer_type (invoke_impl_type);
-    return;
-  }
-  /* APPLE LOCAL end radar 5939894 (C++ ch) */
-
-  push_to_top_level ();
-  invoke_impl_type = start_struct (RECORD_TYPE, get_identifier ("__invoke_impl"));
-
-  /* APPLE LOCAL begin radar 5811599 (C++ ch) */
-  /* void *isa; */
-  field_decl = build_decl (FIELD_DECL, get_identifier ("isa"), ptr_type_node);
-  /* APPLE LOCAL end radar 5811599 (C++ ch) */
+  tree main_type;
+  
+  if (withCopyDispose && descriptor_ptr_type_with_copydispose)
+    return descriptor_ptr_type_with_copydispose;
+  if (!withCopyDispose && descriptor_ptr_type)
+    return descriptor_ptr_type;
+  
+  main_type = 
+    withCopyDispose ? 
+      start_struct (RECORD_TYPE, get_identifier ("__block_descriptor_withcopydispose"))
+      : start_struct (RECORD_TYPE, get_identifier ("__block_descriptor"));
+  
+  /* unsigned long int reserved; */
+  field_decl = build_decl (FIELD_DECL, get_identifier ("reserved"), long_unsigned_type_node);
   field_decl_chain = field_decl;
-
-  /* int32_t Flags; */
-  field_decl = build_decl (FIELD_DECL, get_identifier ("Flags"), unsigned_type_node);
-  chainon (field_decl_chain, field_decl);
-
-  /* int32_t Size */
-  field_decl = build_decl (FIELD_DECL, get_identifier ("Size"), unsigned_type_node);
-  chainon (field_decl_chain, field_decl);
-
-  /* void *FuncPtr; */
-  field_decl = build_decl (FIELD_DECL, get_identifier ("FuncPtr"), ptr_type_node);
+  
+  /* unsigned long int Size; */
+  field_decl = build_decl (FIELD_DECL, get_identifier ("Size"), long_unsigned_type_node);
   chainon (field_decl_chain, field_decl);
-
-  /* APPLE LOCAL begin radar 5811943 - Fix type of pointers to Blocks (C++ ch) */
-  /* Mark this struct as being a block struct rather than a 'normal'
-   struct.  */
-  TYPE_BLOCK_IMPL_STRUCT (invoke_impl_type) = 1;
-  /* APPLE LOCAL end  radar 5811943 - Fix type of pointers to Blocks (C++ ch) */
-  finish_struct (invoke_impl_type, field_decl_chain, NULL_TREE);
-  pop_from_top_level ();
-  invoke_impl_ptr_type = build_pointer_type (invoke_impl_type);
+  
+  if (withCopyDispose)
+  {
+    /* void *CopyFuncPtr; */
+    field_decl = build_decl (FIELD_DECL, get_identifier ("CopyFuncPtr"), ptr_type_node);
+    chainon (field_decl_chain, field_decl);
+    /* void *DestroyFuncPtr; */
+    field_decl = build_decl (FIELD_DECL, get_identifier ("DestroyFuncPtr"), ptr_type_node);
+    chainon (field_decl_chain, field_decl);
+  }
+  
+   /* Mark this struct as being a block struct rather than a 'normal'
+      struct.  */
+  TYPE_BLOCK_IMPL_STRUCT (main_type) = 1;
+  finish_struct (main_type, field_decl_chain, NULL_TREE);
+
+  main_type = build_pointer_type (main_type);
+  if (withCopyDispose)
+    descriptor_ptr_type_with_copydispose = main_type;
+  else
+    descriptor_ptr_type = main_type;
+  return main_type;
 }
-/* APPLE LOCAL end radar 5939894 (C++ ch) */
+/* APPLE LOCAL end radar 5847213 - radar 6329245 */
 
 /* APPLE LOCAL begin radar 5814025 (C++ ch) */
 struct c_declarator *
@@ -8172,12 +8102,6 @@
   struct c_declarator *itarget = target;
   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
 
-  /* APPLE LOCAL begin radar 5732232 - blocks (C++ ch) */
-  /* Closure contructs seen -- generate supporting types.  */
-  if (!invoke_impl_ptr_type)
-    build_block_internal_types ();
-  /* APPLE LOCAL end radar 5732232 - blocks (C++ ch) */
-
   if (type_quals_attrs)
   {
     tree attrs = type_quals_attrs->attrs;
@@ -8401,6 +8325,11 @@
   decl_stmt = build_stmt (DECL_EXPR, decl);
   /* APPLE LOCAL Radar 5811961, Fix location of block prologue vars (C++ ch) */
   SET_EXPR_LOCATION (decl_stmt, DECL_SOURCE_LOCATION (decl));
+  /* APPLE LOCAL begin radar 6163705, Blocks prologues  */
+  /* Give the prologue statements a line number of one before the beginning of
+     the function, to make them easily identifiable later.  */
+  EXPR_LINENO (decl_stmt) =  DECL_SOURCE_LINE (decl) - 1;
+  /* APPLE LOCAL end radar 6163705, Blocks prologues  */
   tsi_link_before (&i, decl_stmt, TSI_SAME_STMT);
 }
 

Modified: llvm-gcc-4.2/trunk/gcc/c-parser.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/c-parser.c?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/c-parser.c (original)
+++ llvm-gcc-4.2/trunk/gcc/c-parser.c Mon Nov  3 01:33:15 2008
@@ -1136,7 +1136,6 @@
 static tree c_parser_asm_statement (c_parser *);
 /* APPLE LOCAL begin radar 5732232 - blocks (C++ ca) */
 static tree c_parser_block_literal_expr (c_parser *);
-static bool c_parser_block_byref_declarations (c_parser *);
 /* APPLE LOCAL end radar 5732232 - blocks (C++ ca) */
 static tree c_parser_asm_operands (c_parser *, bool);
 static tree c_parser_asm_clobbers (c_parser *);
@@ -3765,14 +3764,6 @@
 	  else
 	    goto statement;
 	}
-      /* APPLE LOCAL begin radar 5732232 - blocks (not in C++) */
-      else if (flag_blocks && first_stmt &&
-               c_parser_next_token_is (parser, CPP_OR) &&
-	       c_parser_block_byref_declarations (parser))
-        {
-          ;
-        }
-      /* APPLE LOCAL end radar 5732232 - blocks (not in C++) */
       else if (c_parser_next_token_is (parser, CPP_PRAGMA))
 	{
 	  /* External pragmas, and some omp pragmas, are not associated
@@ -4241,8 +4232,6 @@
   tree block, expr, body, save_break;
   gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH));
   c_parser_consume_token (parser);
-  /* APPLE LOCAL radar 6083129 - byref escapes (C++ cp) */
-  in_bc_stmt_block ();
   block = c_begin_compound_stmt (flag_isoc99);
   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
     {
@@ -4260,8 +4249,6 @@
     add_stmt (build1 (LABEL_EXPR, void_type_node, c_break_label));
   c_break_label = save_break;
   add_stmt (c_end_compound_stmt (block, flag_isoc99));
-  /* APPLE LOCAL radar 6083129 - byref escapes (C++ cp) */
-  outof_bc_stmt_block ();
 }
 
 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
@@ -4286,8 +4273,6 @@
 /* APPLE LOCAL begin for-fsf-4_4 3274130 5295549 */ \
   attrs = c_parser_attributes (parser);
 /* APPLE LOCAL end for-fsf-4_4 3274130 5295549 */ \
-  /* APPLE LOCAL radar 6083129 - byref escapes (C++ cp) */
-  in_bc_stmt_block ();
   block = c_begin_compound_stmt (flag_isoc99);
   loc = c_parser_peek_token (parser)->location;
   cond = c_parser_paren_condition (parser);
@@ -4301,8 +4286,6 @@
 		 true);
 /* APPLE LOCAL end for-fsf-4_4 3274130 5295549 */ \
   add_stmt (c_end_compound_stmt (block, flag_isoc99));
-  /* APPLE LOCAL radar 6083129 - byref escapes (C++ cp) */
-  outof_bc_stmt_block ();
   c_break_label = save_break;
   c_cont_label = save_cont;
 }
@@ -4329,8 +4312,6 @@
 /* APPLE LOCAL begin for-fsf-4_4 3274130 5295549 */ \
   attrs = c_parser_attributes (parser);
 /* APPLE LOCAL end for-fsf-4_4 3274130 5295549 */ \
-  /* APPLE LOCAL radar 6083129 - byref escapes (C++ cp) */
-  in_bc_stmt_block ();
   block = c_begin_compound_stmt (flag_isoc99);
   loc = c_parser_peek_token (parser)->location;
   save_break = c_break_label;
@@ -4350,8 +4331,6 @@
   c_finish_loop (loc, cond, NULL, body, new_break, new_cont, attrs, false);
 /* APPLE LOCAL end for-fsf-4_4 3274130 5295549 */ \
   add_stmt (c_end_compound_stmt (block, flag_isoc99));
-  /* APPLE LOCAL radar 6083129 - byref escapes (C++ cp) */
-  outof_bc_stmt_block ();
 }
 
 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
@@ -4391,8 +4370,6 @@
 /* APPLE LOCAL begin for-fsf-4_4 3274130 5295549 */ \
   attrs = c_parser_attributes (parser);
 /* APPLE LOCAL end for-fsf-4_4 3274130 5295549 */ \
-  /* APPLE LOCAL radar 6083129 - byref escapes (C++ cp) */
-  in_bc_stmt_block ();
   /* APPLE LOCAL radar 4472881 (in 4.2 ah) */
   block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ());
   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
@@ -4518,8 +4495,6 @@
   /* APPLE LOCAL end radar 4708210 (for_objc_collection in 4.2) */
   /* APPLE LOCAL radar 4472881 (in 4.2 ai) */
   add_stmt (c_end_compound_stmt (block, flag_isoc99 || c_dialect_objc ()));
-  /* APPLE LOCAL radar 6083129 - byref escapes (C++ cp) */
-  outof_bc_stmt_block ();
   c_break_label = save_break;
   c_cont_label = save_cont;
 }
@@ -5598,8 +5573,7 @@
            variable holds address of the outside variable referenced in. */
         
         /* APPLE LOCAL begin radar 5932809 - copyable byref blocks (C++ cd) */
-        if (TREE_CODE (expr.value) == VAR_DECL
-            && !building_block_byref_decl)
+        if (TREE_CODE (expr.value) == VAR_DECL)
 	  {
 	    if (BLOCK_DECL_BYREF (expr.value))
 	      {
@@ -5609,7 +5583,7 @@
 		  /* What we have is an expression which is of type 
 		     struct __Block_byref_X. Must get to the value of the variable
 		     embedded in this structure. It is at:
-		     __Block_byref_X.forwarding->x */
+		     __Block_byref_X.__forwarding->x */
 		  expr.value = build_byref_local_var_access (expr.value,
 							     DECL_NAME (orig_decl));
 		}
@@ -6498,6 +6472,12 @@
 	 && c_parser_next_token_is_not (parser, CPP_EOF))
     {
       c_parser_objc_property_attribute (parser);
+      /* APPLE LOCAL begin radar 6302949 */
+      if (c_parser_next_token_is_not (parser, CPP_COMMA)
+	  && c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN)
+	  && c_parser_next_token_is_not (parser, CPP_EOF))
+	warning (0, "property attributes must be separated by a comma");
+      /* APPLE LOCAL end radar 6302949 */
       if (c_parser_next_token_is (parser, CPP_COMMA)
 	  || c_parser_next_token_is (parser, CPP_NAME) /* error */)
 	c_parser_consume_token (parser);
@@ -9386,61 +9366,103 @@
 }
 /* APPLE LOCAL end CW asm blocks */
 /* APPLE LOCAL begin radar 5732232 - blocks (C++ ce) */
-static tree block_copy_assign_decl;
-static tree block_destroy_decl;
+/* APPLE LOCAL begin radar 6175959 */
+static GTY(()) tree block_copy_assign_decl;
+static GTY(()) tree block_object_assign_decl;
+static GTY(()) tree block_destroy_decl;
+static GTY(()) tree block_object_dispose_func_decl;
+/* APPLE LOCAL end radar 6175959 */
+
+/* APPLE LOCAL begin radar 6300081  */
+
+/* This function builds a "generic" block struct type, to be passed 
+   into the debug information for blocks pointers, to allow gdb to
+   find the actual function pointer for the block.  Any time the Blocks
+   structure layout changes, this may also need to change.
+
+   Currently a block pointer is a pointer to a __block_literal_n struct,
+   the third field of which is a pointer to a __block_descriptor struct,
+   whose third field is the function pointer.  There are other fields as
+   well, but these are the ones gdb needs to know about to find the
+   function pointer.  Therefore a generic block struct currently looks
+   like this:
+
+   struct __block_literal_generic 
+   {
+      void * __isa;
+      int __flags;
+      int __reserved;
+      void (*__FuncPtr)(void *);
+      struct __block_descriptor 
+        {
+          unsigned long int reserved;
+	  unsigned long int Size;
+	} *__descriptor;
+   };
 
-void
-gen_block_byref_release_exp (tree var_decl)
-{
-  tree cleanup = build_block_byref_release_exp (var_decl);
-  if (cleanup)
-    add_stmt (cleanup);
-}
+   IF AT ANY TIME THE STRUCTURE OF A __BLOCK_LITERAL_N CHANGES, THIS
+   MUST BE CHANGED ALSO!!
 
-bool building_block_byref_decl = false;
-static bool
-c_parser_block_byref_declarations (c_parser* parser)
+*/
+
+tree
+build_generic_block_struct_type (void)
 {
-  if (!in_imm_block ())
-    return false;
-  warning (0, "| x | has been deprecated in blocks");
-  do {
-    struct c_expr byref_decl_expr;
-    c_parser_consume_token (parser); /* consume '|' or ',' */
-    if (!c_parser_next_token_is (parser, CPP_NAME))
-      {
-	error ("expected identifier in block by-reference variable list");
-	return false;
-      }
-    building_block_byref_decl = true;
-    byref_decl_expr = c_parser_cast_expression (parser, NULL);
-    building_block_byref_decl = false;
-    if (byref_decl_expr.value != error_mark_node &&
-        !(TREE_CODE (byref_decl_expr.value) == VAR_DECL &&
-          (BLOCK_DECL_BYREF (byref_decl_expr.value) ||
-           in_block_global_byref_list (byref_decl_expr.value))))
-      error (
-        "only a visible variable may be used in a block byref declaration");
-  } while (c_parser_next_token_is (parser, CPP_COMMA));
+  tree field_decl_chain;
+  tree field_decl;
+  tree block_struct_type;
 
-  if (!c_parser_next_token_is (parser, CPP_OR))
-    {
-      error ("expected identifier or '|' at end of block by-reference variable list");
-      return false;
-    }
-  c_parser_consume_token (parser); /* consume '|' */
-  return true;
+  push_to_top_level ();
+  block_struct_type = start_struct (RECORD_TYPE, 
+				   get_identifier ("__block_literal_generic"));
+  
+  field_decl = build_decl (FIELD_DECL, get_identifier ("__isa"), ptr_type_node);
+  field_decl_chain = field_decl;
+
+  field_decl = build_decl (FIELD_DECL, get_identifier ("__flags"),
+			   integer_type_node);
+  chainon (field_decl_chain, field_decl);
+
+  field_decl = build_decl (FIELD_DECL, get_identifier ("__reserved"),
+			   integer_type_node);
+  chainon (field_decl_chain, field_decl);
+  
+  /* void *__FuncPtr; */
+  field_decl = build_decl (FIELD_DECL, get_identifier ("__FuncPtr"), ptr_type_node);
+  chainon (field_decl_chain, field_decl);
+
+  field_decl = build_decl (FIELD_DECL, get_identifier ("__descriptor"),
+			   build_block_descriptor_type (false));
+  chainon (field_decl_chain, field_decl);
+
+  TYPE_BLOCK_IMPL_STRUCT (block_struct_type) = 1;
+  finish_struct (block_struct_type, field_decl_chain, NULL_TREE);
+  pop_from_top_level ();
+  return block_struct_type;
 }
+/* APPLE LOCAL end radar 6300081  */
 
+/* APPLE LOCAL begin radar 5847213 - radar 6329245 */
 /** build_block_struct_type -
- struct block_1 {
- struct invok_impl impl;
- void *CopyFuncPtr;   // only if BLOCK_HAS_COPY_DISPOSE is set
- void *DestroyFuncPtr;  // only if BLOCK_HAS_COPY_DISPOSE is set
+ struct __block_literal_n {
+  void *__isa; // initialized to &_NSConcreteStackBlock or &_NSConcreteGlobalBlock
+  int __flags;
+  int __reserved;
+  void *__FuncPtr;
+  struct __block_descriptor {
+    unsigned long int reserved;     // NULL
+    unsigned long int Size;  // sizeof(struct __block_literal_n)
+ 
+    // optional helper functions
+    void *CopyFuncPtr; // When BLOCK_HAS_COPY_DISPOSE
+    void *DestroyFuncPtr; // When BLOCK_HAS_COPY_DISPOSE 
+ } *__descriptor;
+ 
+ // imported variables
  int x; // ref variable list ...
  int *y; // byref variable list
  };
- */
+*/
 static tree
 build_block_struct_type (struct block_sema_info * block_impl)
 {
@@ -9448,9 +9470,6 @@
   char buffer[32];
   static int unique_count;
   tree block_struct_type;
-  /* build struct invok_impl */
-  if (!invoke_impl_ptr_type)
-    build_block_internal_types ();
 
   /* Check and see if this block is required to have a Copy/Dispose
      helper function. If yes, set BlockHasCopyDispose to TRUE. */
@@ -9462,7 +9481,7 @@
       break;
     }
 
-  /* Further check to see that we have __byref variables which require
+  /* Further check to see that we have __block variables which require
      Copy/Dispose helpers. */
   for (chain = block_impl->block_byref_decl_list; chain;
        chain = TREE_CHAIN (chain))
@@ -9472,23 +9491,35 @@
 	break;
       }
 
-  sprintf(buffer, "__block_%d", ++unique_count);
+  sprintf(buffer, "__block_literal_%d", ++unique_count);
   push_to_top_level ();
   block_struct_type = start_struct (RECORD_TYPE, get_identifier (buffer));
-  /* struct invok_impl impl; */
-  field_decl = build_decl (FIELD_DECL, get_identifier ("impl"),
-                           TREE_TYPE (invoke_impl_ptr_type));
+  
+  /* void *__isa; */
+  field_decl = build_decl (FIELD_DECL, get_identifier ("__isa"), ptr_type_node);
   field_decl_chain = field_decl;
+  
+  /* int __flags */
+  field_decl = build_decl (FIELD_DECL, get_identifier ("__flags"),
+			   integer_type_node);
+  chainon (field_decl_chain, field_decl);
+
+  /* int __reserved */
+  field_decl = build_decl (FIELD_DECL, get_identifier ("__reserved"),
+			   integer_type_node);
+  chainon (field_decl_chain, field_decl);
+  
+  /* void *__FuncPtr; */
+  field_decl = build_decl (FIELD_DECL, get_identifier ("__FuncPtr"), ptr_type_node);
+  chainon (field_decl_chain, field_decl);
+
+  /* struct __block_descriptor *__descriptor */
+  field_decl = build_decl (FIELD_DECL, get_identifier ("__descriptor"),
+                           build_block_descriptor_type (block_impl->BlockHasCopyDispose));
+  chainon (field_decl_chain, field_decl);
+  
   if (block_impl->BlockHasCopyDispose)
   {
-    /* void *CopyFuncPtr; */
-    field_decl = build_decl (FIELD_DECL, get_identifier ("CopyFuncPtr"),
-                             ptr_type_node);
-    chainon (field_decl_chain, field_decl);
-    /* void *DestroyFuncPtr; */
-    field_decl = build_decl (FIELD_DECL, get_identifier ("DestroyFuncPtr"),
-                             ptr_type_node);
-    chainon (field_decl_chain, field_decl);
     /* If inner block of a nested block has BlockHasCopyDispose, so
        does its outer block. */
     if (block_impl->prev_block_info)
@@ -9521,28 +9552,98 @@
   return block_struct_type;
 }
 
+/** build_descriptor_block_decl -
+  This routine builds a static block_descriptior variable of type:
+  struct __block_descriptor; and initializes it to:
+  {0, sizeof(struct literal_block_n), 
+   copy_helper_block_1, // only if block BLOCK_HAS_COPY_DISPOSE
+   destroy_helper_block_1, // only if block BLOCK_HAS_COPY_DISPOSE
+  }
+*/
+static tree
+build_descriptor_block_decl (tree block_struct_type, struct block_sema_info *block_impl)
+{
+  extern tree create_tmp_var_raw (tree, const char *);
+  static int desc_unique_count;
+  int size;
+  tree helper_addr, fields;
+  tree decl, constructor, initlist;
+  tree exp, bind;
+  char name [32];
+  tree descriptor_type =  
+    TREE_TYPE (build_block_descriptor_type (block_impl->BlockHasCopyDispose));
+
+  sprintf (name, "__block_descriptor_tmp_%d", ++desc_unique_count);
+  decl = create_tmp_var_raw (descriptor_type, name);
+  DECL_CONTEXT (decl) = NULL_TREE;
+  DECL_ARTIFICIAL (decl) = 1;
+
+  /* Initialize "reserved" field to 0 for now. */
+  fields = TYPE_FIELDS (descriptor_type);
+  initlist = build_tree_list (fields, build_int_cst (long_unsigned_type_node, 0));
+  fields = TREE_CHAIN (fields);
+  
+  /* Initialize "Size" field. */
+  size = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (block_struct_type));
+  initlist = tree_cons (fields,
+                        build_int_cst (long_unsigned_type_node, size),
+                        initlist);
+
+  if (block_impl->BlockHasCopyDispose)
+    {
+      /* Initialize "CopyFuncPtr" and "DestroyFuncPtr" fields. */
+      /* Helpers were previously generated completeley as a nested
+	 function (and context was required for code gen.) But they are not, 
+	 so context must be set to NULL so initialization logic does not complain. */
+      DECL_CONTEXT (block_impl->copy_helper_func_decl) = NULL_TREE;
+      fields = TREE_CHAIN (fields);
+      helper_addr = build_fold_addr_expr (block_impl->copy_helper_func_decl);
+      helper_addr = convert (ptr_type_node, helper_addr);
+      initlist = tree_cons (fields, helper_addr, initlist);
+      DECL_CONTEXT (block_impl->destroy_helper_func_decl) = NULL_TREE;
+      fields = TREE_CHAIN (fields);
+      helper_addr = build_fold_addr_expr (block_impl->destroy_helper_func_decl);
+      helper_addr = convert (ptr_type_node, helper_addr);
+      initlist = tree_cons (fields, helper_addr, initlist);
+    }
+  constructor = build_constructor_from_list (descriptor_type,
+                                             nreverse (initlist));
+  TREE_CONSTANT (constructor) = 1;
+  TREE_STATIC (constructor) = 1;
+  TREE_READONLY (constructor) = 1;
+  DECL_INITIAL (decl) = constructor;
+  exp = build_stmt (DECL_EXPR, decl);
+  bind = build3 (BIND_EXPR, void_type_node, decl, exp, NULL);
+  TREE_SIDE_EFFECTS (bind) = 1;
+  add_stmt (bind);
+  TREE_PUBLIC (decl) = 0;
+  TREE_STATIC (decl) = 1;
+  finish_decl (decl, constructor, NULL_TREE);
+  return decl;
+}
+
 /**
  build_block_struct_initlist - builds the initializer list:
- { &_NSConcreteStackBlock or &_NSConcreteGlobalBlock // isa,
-   BLOCK_HAS_COPY_DISPOSE | BLOCK_IS_GLOBAL // flags,
- sizeof(struct block_1),
- helper_1 },
- copy_helper_block_1, // only if block BLOCK_HAS_COPY_DISPOSE
- destroy_helper_block_1, // only if block BLOCK_HAS_COPY_DISPOSE
- x,
- &y
+ { &_NSConcreteStackBlock or &_NSConcreteGlobalBlock // __isa,
+   BLOCK_HAS_DESCRIPTOR | BLOCK_HAS_COPY_DISPOSE | BLOCK_IS_GLOBAL // __flags,
+   0, // __reserved
+   &helper_1, // __FuncPtr,
+   &static_descriptor_variable // __descriptor,
+   x, // user variables.
+   &y
+   ...
  }
 */
 static tree
 build_block_struct_initlist (tree block_struct_type,
 			     struct block_sema_info *block_impl)
 {
-  tree initlist;
-  int size;
-  tree helper_addr, chain, fields;
-  unsigned flags = 0;
+  tree initlist, helper_addr;
+  tree chain, fields;
+  unsigned int flags = BLOCK_HAS_DESCRIPTOR;
   static tree NSConcreteStackBlock_decl = NULL_TREE;
   static tree NSConcreteGlobalBlock_decl = NULL_TREE;
+  tree descriptor_block_decl = build_descriptor_block_decl (block_struct_type, block_impl);
 
   if (block_impl->BlockHasCopyDispose)
     /* Note! setting of this flag merely indicates to the runtime that
@@ -9550,9 +9651,12 @@
        routines. */
     flags |= BLOCK_HAS_COPY_DISPOSE;
 
-  fields = TYPE_FIELDS (TREE_TYPE (invoke_impl_ptr_type));
-
-  if (!current_function_decl)
+  fields = TYPE_FIELDS (block_struct_type);
+  /* APPLE LOCAL begin radar 6230297 */
+  if (!current_function_decl || 
+      (block_impl->block_ref_decl_list == NULL_TREE &&
+       block_impl->block_byref_decl_list == NULL_TREE))
+  /* APPLE LOCAL end radar 6230297 */
     {
       /* This is a global block. */
       /* Find an existing declaration for _NSConcreteGlobalBlock or declare
@@ -9596,34 +9700,28 @@
     }
   fields = TREE_CHAIN (fields);
 
+  /* __flags */
   initlist = tree_cons (fields,
-                        build_int_cst (unsigned_type_node, flags),
+                        build_int_cst (integer_type_node, flags),
                         initlist);
   fields = TREE_CHAIN (fields);
-  size = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (block_struct_type));
+
+  /* __reserved */
   initlist = tree_cons (fields,
-                        build_int_cst (unsigned_type_node, size),
+                        build_int_cst (integer_type_node, 0),
                         initlist);
   fields = TREE_CHAIN (fields);
+
+  /* __FuncPtr */
   helper_addr = build_fold_addr_expr (block_impl->helper_func_decl);
   helper_addr = convert (ptr_type_node, helper_addr);
   initlist = tree_cons (fields, helper_addr, initlist);
-  gcc_assert (invoke_impl_ptr_type);
-  initlist = build_constructor_from_list (TREE_TYPE (invoke_impl_ptr_type),
-                                          nreverse (initlist));
-  fields = TYPE_FIELDS (block_struct_type);
-  initlist = build_tree_list (fields, initlist);
-  if (block_impl->BlockHasCopyDispose)
-    {
-      fields = TREE_CHAIN (fields);
-      helper_addr = build_fold_addr_expr (block_impl->copy_helper_func_decl);
-      helper_addr = convert (ptr_type_node, helper_addr);
-      initlist = tree_cons (fields, helper_addr, initlist);
-      fields = TREE_CHAIN (fields);
-      helper_addr = build_fold_addr_expr (block_impl->destroy_helper_func_decl);
-      helper_addr = convert (ptr_type_node, helper_addr);
-      initlist = tree_cons (fields, helper_addr, initlist);
-    }
+  fields = TREE_CHAIN (fields);
+
+  /* __descriptor */
+  initlist = tree_cons (fields,
+			convert (ptr_type_node, build_fold_addr_expr (descriptor_block_decl)),
+			initlist);
   for (chain = block_impl->block_original_ref_decl_list; chain;
        chain = TREE_CHAIN (chain))
     {
@@ -9632,14 +9730,30 @@
       fields = TREE_CHAIN (fields);
       initlist = tree_cons (fields, copy_in_object (y), initlist);
     }
-  for (chain = block_impl->block_original_byref_decl_list; chain;
+  for (chain = block_impl->block_byref_decl_list; chain;
        chain = TREE_CHAIN (chain))
     {
-      tree y = TREE_VALUE (chain);
+      tree y = lookup_name (DECL_NAME (TREE_VALUE (chain)));
+      tree forwarding_expr;
+      gcc_assert (y);
       TREE_USED (y) = 1;
+      if (COPYABLE_BYREF_LOCAL_VAR (y))
+        {
+	  /* For variables declared __block, either the original one
+	     at the point of declaration or the imported version (which is
+	     initialized in the helper function's prologue) is used to 
+	     initilize the byref variable field in the temporary. */
+          if (TREE_CODE (TREE_TYPE (y)) != RECORD_TYPE)
+            y = build_indirect_ref (y, "unary *");
+	  /* We will be using the __block_struct_variable.__forwarding as the 
+	     initializer. */
+          forwarding_expr = build_component_ref (y, get_identifier ("__forwarding"));
+        }
+      else
+	/* Global variable is always assumed passed by its address. */
+	forwarding_expr = build_fold_addr_expr (y);
       fields = TREE_CHAIN (fields);
-      y = build_fold_addr_expr (y);
-      initlist = tree_cons (fields, y, initlist);
+      initlist = tree_cons (fields, forwarding_expr, initlist);
     }
   return initlist;
 }
@@ -9648,29 +9762,39 @@
  build_block_literal_tmp - This routine:
 
  1) builds block type:
- struct block_1 {
- struct invok_impl impl;
- void *CopyFuncPtr;    // only if block BLOCK_HAS_COPY_DISPOSE
- void *DestroyFuncPtr; // only if block BLOCK_HAS_COPY_DISPOSE
+ struct __block_literal_n {
+  void *__isa; // initialized to &_NSConcreteStackBlock or &_NSConcreteGlobalBlock
+  int __flags;
+  int __reserved;
+  void *__FuncPtr
+  struct __block_descriptor {
+    unsigned long int reserved;     // NULL
+    unsigned long int Size;  // sizeof(struct Block_literal_1)
+
+    // optional helper functions
+    void *CopyFuncPtr; // When BLOCK_HAS_COPY_DISPOSE
+    void *DestroyFuncPtr; // When BLOCK_HAS_COPY_DISPOSE
+ } *__descriptor;
+
+ // imported variables
  int x; // ref variable list ...
  int *y; // byref variable list
  };
 
  2) build function prototype:
- double helper_1(struct block_1 *ii, int z);
+ double helper_1(struct __block_literal_n *ii, int z);
 
  3) build the temporary initialization:
- struct block_1 I = {
- { &_NSConcreteStackBlock or &_NSConcreteGlobalBlock // isa,
-   BLOCK_HAS_COPY_DISPOSE | BLOCK_IS_GLOBAL // flags,
-   sizeof(struct block_1),
-   helper_1 },
- copy_helper_block_1, // only if block BLOCK_HAS_COPY_DISPOSE
- destroy_helper_block_1, // only if block BLOCK_HAS_COPY_DISPOSE
- x,
- &y
-};
-
+ struct __block_literal_n I = {
+   &_NSConcreteStackBlock or &_NSConcreteGlobalBlock // __isa,
+   BLOCK_HAS_DESCRIPTOR | BLOCK_HAS_COPY_DISPOSE | BLOCK_IS_GLOBAL // __flags,
+   0, // __reserved
+   &helper_1, // __FuncPtr 
+   &static_descriptor_variable // __descriptor,
+   x, // user variables.
+   &y
+   ...
+ };
 It return the temporary.
 */
 
@@ -9683,12 +9807,22 @@
   tree constructor, initlist;
   tree exp, bind;
   tree block_struct_type = TREE_TYPE (block_impl->block_arg_ptr_type);
+  /* APPLE LOCAL begin radar 6230297 */
+  bool staticBlockTmp = (block_impl->block_ref_decl_list == NULL_TREE &&
+                         block_impl->block_byref_decl_list == NULL_TREE);
 
 
   block_holder_tmp_decl = create_tmp_var_raw (block_struct_type, name);
   /* Context will not be known until when the literal is synthesized.
      This is more so in the case of nested block literal blocks.  */
-  DECL_CONTEXT (block_holder_tmp_decl) = current_function_decl;
+  DECL_CONTEXT (block_holder_tmp_decl) = staticBlockTmp ? NULL_TREE 
+                                                        : current_function_decl;
+  /* In the new ABI, helper function decl. is the initializer for the
+     descriptor variable which is always declared static. So, it must
+     have no context; otherwise, gcc thinks that it requires trampoline! when
+     address of this function is used as initializer. */
+  DECL_CONTEXT (block_impl->helper_func_decl) = NULL_TREE;
+  /* APPLE LOCAL end radar 6230297 */
   DECL_ARTIFICIAL (block_holder_tmp_decl) = 1;
 
   initlist = build_block_struct_initlist (block_struct_type,
@@ -9705,13 +9839,15 @@
   TREE_SIDE_EFFECTS (bind) = 1;
   add_stmt (bind);
   /* Temporary representing a global block is made global static.  */
-  if (global_bindings_p ()) {
+  /* APPLE LOCAL radar 6230297 */
+  if (staticBlockTmp || global_bindings_p ()) {
     TREE_PUBLIC (block_holder_tmp_decl) = 0;
     TREE_STATIC (block_holder_tmp_decl) = 1;
     finish_decl (block_holder_tmp_decl, constructor, NULL_TREE);
   }
   return block_holder_tmp_decl;
 }
+/* APPLE LOCAL end radar 5847213 - radar 6329245 */
 
 static tree
 clean_and_exit (tree block)
@@ -9739,7 +9875,8 @@
   DECL_ARG_TYPE (dst_arg) = block_impl->block_arg_ptr_type;
   src_arg = build_decl (PARM_DECL, get_identifier ("_src"),
                         block_impl->block_arg_ptr_type);
-  DECL_CONTEXT (dst_arg) = cur_block->copy_helper_func_decl;
+  /* APPLE LOCAL radar 5847213 */
+  DECL_CONTEXT (src_arg) = cur_block->copy_helper_func_decl;
   TREE_USED (src_arg) = 1;
   DECL_ARG_TYPE (src_arg) = block_impl->block_arg_ptr_type;
   arg_info = xcalloc (1, sizeof (struct c_arg_info));
@@ -9760,6 +9897,9 @@
        chain = TREE_CHAIN (chain))
     if (block_requires_copying (TREE_VALUE (chain)))
     {
+      /* APPLE LOCAL begin radar 6175959 */
+      tree which_function_decl;
+      tree func_params, call_exp;
       tree p = TREE_VALUE (chain);
       tree dst_block_component, src_block_component;
       dst_block_component = build_component_ref (build_indirect_ref (dst_arg, "->"),
@@ -9769,40 +9909,58 @@
 
       if (TREE_CODE (TREE_TYPE (p)) == BLOCK_POINTER_TYPE)
       {
-        tree func_params, call_exp;
-        /* _Block_copy_assign(&_dest->myImportedBlock, _src->myImportedClosure) */
-        /* Build a: void _Block_copy_assign (void *, void *) if not done
+        /* _Block_copy_assign(&_dest->myImportedBlock, _src->myImportedClosure, 0) */
+        /* Build a: void _Block_copy_assign (void *, void *, int) if not done
            already. */
-        if (!block_copy_assign_decl)
+        /* APPLE LOCAL begin radar 6310599 */
+        if (!block_copy_assign_decl &&
+	    !(block_copy_assign_decl = lookup_name (get_identifier ("_Block_copy_assign"))))
+        /* APPLE LOCAL end radar 6310599 */
         {
           tree func_type =
             build_function_type (void_type_node,
               tree_cons (NULL_TREE, ptr_type_node,
-                         tree_cons (NULL_TREE, ptr_type_node, void_list_node)));
+                         tree_cons (NULL_TREE, ptr_type_node, 
+				    tree_cons (NULL_TREE, integer_type_node, void_list_node))));
 
           block_copy_assign_decl = builtin_function ("_Block_copy_assign", func_type,
 						     0, NOT_BUILT_IN, 0, NULL_TREE);
           TREE_NOTHROW (block_copy_assign_decl) = 0;
         }
-        dst_block_component = build_fold_addr_expr (dst_block_component);
-        func_params = tree_cons (NULL_TREE, dst_block_component,
-                                 tree_cons (NULL_TREE, src_block_component,
-                                            NULL_TREE));
-        call_exp = build_function_call (block_copy_assign_decl, func_params);
-        add_stmt (call_exp);
+	which_function_decl = block_copy_assign_decl;
       }
       else
       {
-        /* _dest-> imported_object_x = [_src->imported_object_x retain] */
-        tree rhs, store;
-        /* [_src->imported_object_x retain] */
-        rhs = retain_block_component (src_block_component);
-        store = build_modify_expr (dst_block_component, NOP_EXPR, rhs);
-        add_stmt (store);
+        /* _Block_object_assign(&_dest->myImportedBlock, _src->myImportedClosure, 0) */
+        /* Build a: void _Block_object_assign (void *, void *, int) if not done
+           already. */
+        if (!block_object_assign_decl &&
+	    !(block_object_assign_decl = lookup_name (get_identifier ("_Block_object_assign"))))
+        {
+          tree func_type =
+            build_function_type (void_type_node,
+              tree_cons (NULL_TREE, ptr_type_node,
+                         tree_cons (NULL_TREE, ptr_type_node, 
+				    tree_cons (NULL_TREE, integer_type_node, void_list_node))));
+
+          block_object_assign_decl = builtin_function ("_Block_object_assign", func_type,
+						     0, NOT_BUILT_IN, 0, NULL_TREE);
+          TREE_NOTHROW (block_object_assign_decl) = 0;
+        }
+	which_function_decl = block_object_assign_decl;
       }
+      dst_block_component = build_fold_addr_expr (dst_block_component);
+      func_params = tree_cons (NULL_TREE, dst_block_component,
+                               tree_cons (NULL_TREE, src_block_component,
+                                          tree_cons (NULL_TREE, 
+				                     build_int_cst (integer_type_node, 0), 
+				       		     NULL_TREE)));
+      call_exp = build_function_call (which_function_decl, func_params);
+      add_stmt (call_exp);
+      /* APPLE LOCAL end radar 6175959 */
     }
 
-  /* For each __byref declared variable used in |...| Must generate call to:
+  /* For each __block declared variable must generate call to:
      _Block_byref_assign_copy(&_dest->myImportedBlock, _src->myImportedBlock)
   */
   for (chain = block_impl->block_byref_decl_list; chain;
@@ -9833,6 +9991,30 @@
   free (arg_info);
 }
 
+/* APPLE LOCAL begin radar 6175959 */
+static tree 
+block_object_dispose (tree src_block_component)
+{
+  tree func_params;
+  if (!block_object_dispose_func_decl &&
+      !(block_object_dispose_func_decl = lookup_name (get_identifier ("_Block_object_dispose"))))
+    {
+      tree func_type =
+      build_function_type (void_type_node,
+                           tree_cons (NULL_TREE, ptr_type_node,
+                                      tree_cons (NULL_TREE, integer_type_node, void_list_node)));
+
+      block_object_dispose_func_decl = builtin_function ("_Block_object_dispose", func_type,
+                                       0, NOT_BUILT_IN, 0, NULL_TREE);
+     TREE_NOTHROW (block_object_dispose_func_decl) = 0;
+    }
+    func_params = tree_cons (NULL_TREE, src_block_component,
+                             tree_cons (NULL_TREE,
+                                        build_int_cst (integer_type_node, 0), NULL_TREE));
+    return build_function_call (block_object_dispose_func_decl, func_params);
+}
+/* APPLE LOCAL end radar 6175959 */
+
 static void
 synth_destroy_helper_block_func (struct block_sema_info * block_impl)
 {
@@ -9860,6 +10042,7 @@
        chain = TREE_CHAIN (chain))
     if (block_requires_copying (TREE_VALUE (chain)))
     {
+      /* APPLE LOCAL begin radar 6175959 */
       tree p = TREE_VALUE (chain);
       tree src_block_component;
       src_block_component = build_component_ref (build_indirect_ref (src_arg, "->"),
@@ -9876,26 +10059,30 @@
         {
           tree func_type =
           build_function_type (void_type_node,
-                               tree_cons (NULL_TREE, ptr_type_node, void_list_node));
+                               tree_cons (NULL_TREE, ptr_type_node, 
+					  tree_cons (NULL_TREE, integer_type_node, void_list_node)));
 
           block_destroy_decl = builtin_function ("_Block_destroy", func_type,
 						 0, NOT_BUILT_IN, 0, NULL_TREE);
           TREE_NOTHROW (block_destroy_decl) = 0;
         }
-        func_params = tree_cons (NULL_TREE, src_block_component, NULL_TREE);
+        func_params = tree_cons (NULL_TREE, src_block_component, 
+				 tree_cons (NULL_TREE, 
+					    build_int_cst (integer_type_node, 0), NULL_TREE));
         call_exp = build_function_call (block_destroy_decl, func_params);
         add_stmt (call_exp);
       }
       else
       {
         tree rel_exp;
-        /* [_src->imported_object_0 release]; */
-        rel_exp = release_block_component (src_block_component);
+	/* _Block_object_dispose(_src->imported_object_0, 0); */
+        rel_exp = block_object_dispose (src_block_component);
         add_stmt (rel_exp);
       }
+      /* APPLE LOCAL end radar 6175959 */
     }
 
-  /* For each __byref declared variable used in |...| Must generate call to:
+  /* For each __block declared variable must generate call to:
    _Block_byref_release(_src->myImportedClosure)
    */
   for (chain = block_impl->block_byref_decl_list; chain;
@@ -10078,6 +10265,8 @@
   /* APPLE LOCAL begin radar 6237713 */
   if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
     attributes = c_parser_attributes (parser);
+  /* APPLE LOCAL radar 6246527 */
+  any_recognized_block_attribute (attributes);
   decl_attributes (&cur_block->helper_func_decl, attributes, 0);
   /* APPLE LOCAL end radar 6237713 */
   

Modified: llvm-gcc-4.2/trunk/gcc/c-typeck.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/c-typeck.c?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/c-typeck.c (original)
+++ llvm-gcc-4.2/trunk/gcc/c-typeck.c Mon Nov  3 01:33:15 2008
@@ -76,9 +76,6 @@
 static int require_constant_elements;
 
 /* APPLE LOCAL begin radar 5732232 - blocks (C++ cm) */
-/* APPLE LOCAL begin radar 5811943 - Fix type of pointers to Blocks  */
-/* Move declaration of invoke_impl_ptr_type to c-common.c  */
-/* APPLE LOCAL end radar 5811943 - Fix type of pointers to Blocks  */
 static bool types_are_block_compatible (tree lhptee, tree rhptee);
 static tree build_block_call (tree, tree, tree);
 /* APPLE LOCAL end radar 5732232 - blocks (C++ cm) */
@@ -2195,9 +2192,7 @@
 		   (DECL_EXTERNAL (decl) || TREE_STATIC (decl)));
 	  /* Treat all 'global' variables as 'byref' by default. */
           /* APPLE LOCAL begin radar 6014138 (C++ ci) */
-	  if (building_block_byref_decl || gdecl 
-              || (TREE_CODE (decl) == VAR_DECL 
-                  && COPYABLE_BYREF_LOCAL_VAR (decl)))
+	  if (gdecl || (TREE_CODE (decl) == VAR_DECL && COPYABLE_BYREF_LOCAL_VAR (decl)))
           /* APPLE LOCAL end radar 6014138 (C++ ci) */
 	    {
 	      /* APPLE LOCAL begin radar 5803600 (C++ ci) */
@@ -3692,8 +3687,8 @@
 	}
       /* APPLE LOCAL begin 4154928 */
       /* Objective-C pointer comparisons are a bit more lenient.  */
-      /* APPLE LOCAL radar 4229905 */
-      else if (objc_have_common_type (type1, type2, -3, NULL_TREE))
+      /* APPLE LOCAL radar 4229905 - radar 6231433 */
+      else if (objc_have_common_type (type1, type2, -3, NULL_TREE, "conditional expression"))
 	result_type = objc_common_type (type1, type2);
       /* APPLE LOCAL end 4154928 */
       else
@@ -4076,39 +4071,40 @@
   return false;
 }
 
+/* APPLE LOCAL begin radar 5847213 - radar 6329245 */
 /**
  build_block_call - Routine to build a block call; as in:
-  ((double(*)(struct invok_impl *, int))(BLOCK_PTR_VAR->FuncPtr))(I, 42);
+  ((double(*)(void *, int))(BLOCK_PTR_EXP->__FuncPtr))(I, 42);
  FNTYPE is the original function type derived from the syntax.
- FUNCTION is the4 block pointer variable.
+ BLOCK_PTR_EXP is the block pointer variable.
  PARAMS is the parameter list.
 */
 static tree
-build_block_call (tree fntype, tree function, tree params)
+build_block_call (tree fntype, tree block_ptr_exp, tree params)
 {
-  tree block_ptr_exp;
   tree function_ptr_exp;
   tree typelist;
 
-  /* (struct invok_impl *)BLOCK_PTR_VAR */
-  /* First convert it to 'void *'. */
-  block_ptr_exp = convert (ptr_type_node, function);
-  gcc_assert (invoke_impl_ptr_type);
-  block_ptr_exp = convert (invoke_impl_ptr_type, block_ptr_exp);
-  params = tree_cons (NULL_TREE, block_ptr_exp, params);
-  /* BLOCK_PTR_VAR->FuncPtr */
-  function_ptr_exp =
-    build_component_ref (build_indirect_ref (block_ptr_exp, "->"),
-                         get_identifier ("FuncPtr"));
+  /* First convert BLOCK_PTR_EXP to 'void *'. */
+  block_ptr_exp = convert (ptr_type_node, block_ptr_exp);
+  gcc_assert (generic_block_literal_struct_type);
+  block_ptr_exp = convert (build_pointer_type (generic_block_literal_struct_type),
+			   block_ptr_exp);
+  /* BLOCK_PTR_VAR->__FuncPtr */
+  function_ptr_exp = build_component_ref (build_indirect_ref (block_ptr_exp, "->"),
+					  get_identifier ("__FuncPtr"));
+  gcc_assert (function_ptr_exp);
 
-  /* Build: result_type(*)(struct invok_impl *, function-arg-type-list) */
+  /* Build: result_type(*)(void *, function-arg-type-list) */
   typelist = TYPE_ARG_TYPES (fntype);
-  typelist = tree_cons (NULL_TREE, invoke_impl_ptr_type, typelist);
+  typelist = tree_cons (NULL_TREE, ptr_type_node, typelist);
   fntype = build_function_type (TREE_TYPE (fntype), typelist);
   function_ptr_exp = convert (build_pointer_type (fntype), function_ptr_exp);
+  params = tree_cons (NULL_TREE, block_ptr_exp, params);
   return fold_build3 (CALL_EXPR, TREE_TYPE (fntype),
                       function_ptr_exp, params, NULL_TREE);
 }
+/* APPLE LOCAL end radar 5847213 - radar 6329245 */
 /* APPLE LOCAL end radar 5732232 - blocks (C++ cm) */
 
 /* Interpret a cast of expression EXPR to type TYPE.  */
@@ -4350,7 +4346,8 @@
 	  break;
 	}
 
-      objc_ok = objc_compare_types (type, rhstype, parmno, rname);
+      /* APPLE LOCAL radar 6231433 */
+      objc_ok = objc_compare_types (type, rhstype, parmno, rname, "comparison");
     }
 
   if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
@@ -5260,7 +5257,8 @@
 	  /* APPLE LOCAL begin radar 4293709 */
           if (c_dialect_objc ())
 	    (void)objc_compare_types (type, TREE_TYPE (inside_init), 
-				      -2/* init */, NULL_TREE);
+				      /* APPLE LOCAL radar 6231433 */
+				      -2/* init */, NULL_TREE, NULL);
 	  /* APPLE LOCAL end radar 4293709 */
 	}
 
@@ -7543,8 +7541,7 @@
       nlist->label = decl;
       label_context_stack_vm->labels_used = nlist;
     }
-  /* APPLE LOCAL radar 6083129 - byref escapes (C++ cp) */
-  diagnose_byref_var_in_current_scope ();
+
   TREE_USED (decl) = 1;
   return add_stmt (build1 (GOTO_EXPR, void_type_node, decl));
 }
@@ -7875,8 +7872,7 @@
 
       retval = build2 (MODIFY_EXPR, TREE_TYPE (res), res, t);
     }
-  /* APPLE LOCAL radar 6083129 - byref escapes (C++ cp) */
-  release_all_local_byrefs_at_return ();
+
   ret_stmt = build_stmt (RETURN_EXPR, retval);
   TREE_NO_WARNING (ret_stmt) |= no_warning;
   return add_stmt (ret_stmt);
@@ -8222,11 +8218,6 @@
 
   if (skip)
     return NULL_TREE;
-  /* APPLE LOCAL begin radar 6083129 - byref escapes (C++ cp) */
-  /* Before breaking out or on continue, release all local __byref
-     variables which go out of scope. */
-  release_local_byrefs_at_break ();
-  /* APPLE LOCAL end radar 6083129 - byref escapes  (C++ cp) */
 
   return add_stmt (build1 (GOTO_EXPR, void_type_node, label));
 }
@@ -8688,7 +8679,8 @@
       return error_mark_node;
     }
 
-  objc_ok = objc_compare_types (type0, type1, -3, NULL_TREE);
+  /* APPLE LOCAL radar 6231433 */
+  objc_ok = objc_compare_types (type0, type1, -3, NULL_TREE, "comparison");
 
   switch (code)
     {

Modified: llvm-gcc-4.2/trunk/gcc/config/darwin-c.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/config/darwin-c.c?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/config/darwin-c.c (original)
+++ llvm-gcc-4.2/trunk/gcc/config/darwin-c.c Mon Nov  3 01:33:15 2008
@@ -1086,8 +1086,6 @@
   /* APPLE LOCAL end ObjC GC */
   /* APPLE LOCAL begin radar 5932809 - copyable byref blocks */
   if (flag_blocks) {
-    /* APPLE LOCAL radar 6096219 */
-    builtin_define ("__byref=__attribute__((__blocks__(byref)))");
     builtin_define ("__block=__attribute__((__blocks__(byref)))");
   }
   /* APPLE LOCAL radar 6230656 */

Modified: llvm-gcc-4.2/trunk/gcc/config/darwin-sections.def
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/config/darwin-sections.def?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/config/darwin-sections.def (original)
+++ llvm-gcc-4.2/trunk/gcc/config/darwin-sections.def Mon Nov  3 01:33:15 2008
@@ -89,7 +89,8 @@
 	     ".section __TEXT,__picsymbolstub4,symbol_stubs,none,16", 0)
 /* APPLE LOCAL end ARM pic support */
 DEF_SECTION (darwin_exception_section, 0,
-	     ".section __DATA,__gcc_except_tab", 0)
+	    /* APPLE LOCAL EH __TEXT __gcc_except_tab 5819051 */
+	     ".section __TEXT,__gcc_except_tab", 0)
 DEF_SECTION (darwin_eh_frame_section, 0,
 	     ".section " EH_FRAME_SECTION_NAME ",__eh_frame"
 	     EH_FRAME_SECTION_ATTR, 0)
@@ -98,6 +99,12 @@
 DEF_SECTION (objc_v2_message_refs_section, 0,
 	     ".section __DATA, __objc_msgrefs, coalesced", 0)
 /* APPLE LOCAL end radar 5575115 */
+/* APPLE LOCAL begin radar 6255595 */
+DEF_SECTION (objc_v2_classdefs_section, 0,
+	     ".section __DATA, __objc_data", 0)
+DEF_SECTION (objc_v2_metadata_section, 0,
+	     ".section __DATA, __objc_const", 0)
+/* APPLE LOCAL end radar 6255595 */
 DEF_SECTION (objc_v2_classrefs_section, 0, 
              ".section __DATA, __objc_classrefs, regular, no_dead_strip", 1)
 DEF_SECTION (objc_v2_classlist_section, 0,

Modified: llvm-gcc-4.2/trunk/gcc/config/darwin.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/config/darwin.c?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/config/darwin.c (original)
+++ llvm-gcc-4.2/trunk/gcc/config/darwin.c Mon Nov  3 01:33:15 2008
@@ -148,6 +148,10 @@
       static const enum darwin_section_enum tomarkv2[] =
 	{
 	  objc_v2_message_refs_section,
+	  /* APPLE LOCAL begin radar 6255595 */
+	  objc_v2_classdefs_section,
+	  objc_v2_metadata_section,
+	  /* APPLE LOCAL end radar 6255595 */
 	  objc_v2_classrefs_section,
 	  objc_v2_classlist_section,
 	  objc_v2_categorylist_section,
@@ -1325,6 +1329,30 @@
   return MACHOPIC_INDIRECT ? 3 : 0;
 }
 
+/* APPLE LOCAL begin radar 5575115, 6255595 */
+/* This routine returns TRUE if EXP is a variable representing
+   on objective C meta data. */
+static inline bool
+objc_internal_variable_name (tree exp)
+{
+  if (TREE_CODE (exp) == VAR_DECL)
+    {
+      tree decl_name = DECL_NAME (exp);
+      if (decl_name && TREE_CODE (decl_name) == IDENTIFIER_NODE
+	  && IDENTIFIER_POINTER (decl_name))
+	{
+	  const char* name = IDENTIFIER_POINTER (decl_name);
+	  return 
+	   (!strncmp (name, "_OBJC_", 6)
+	    || !strncmp (name, "OBJC_", 5)
+	    || !strncmp (name, "l_OBJC_", 7)
+            || !strncmp (name, "l_objc_", 7));
+	}
+    }
+  return false;
+}
+/* APPLE LOCAL end radar 5575115, 6255595 */
+
 section *
 machopic_select_section (tree exp, int reloc,
 			 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
@@ -1423,14 +1451,9 @@
       else
 	return base_section;
     }
-  else if (TREE_CODE (exp) == VAR_DECL &&
-	   DECL_NAME (exp) &&
-	   TREE_CODE (DECL_NAME (exp)) == IDENTIFIER_NODE &&
-	   IDENTIFIER_POINTER (DECL_NAME (exp)) &&
-           /* APPLE LOCAL begin radar 5575115 */
-	   (!strncmp (IDENTIFIER_POINTER (DECL_NAME (exp)), "_OBJC_", 6)
-            || !strncmp (IDENTIFIER_POINTER (DECL_NAME (exp)), "l_objc_", 7)))
-           /* APPLE LOCAL end radar 5575115 */
+  /* APPLE LOCAL begin radar 5575115, 6255595 */
+  else if (objc_internal_variable_name (exp))
+  /* APPLE LOCAL end radar 5575115, 6255595 */
     {
       const char *name = IDENTIFIER_POINTER (DECL_NAME (exp));
       /* APPLE LOCAL begin radar 4792158 */
@@ -1505,8 +1528,8 @@
             return darwin_sections[objc_v2_classrefs_section];
           else if (!strncmp (name, "_OBJC_CLASSLIST_SUP_REFS_", 25))
             return darwin_sections[objc_v2_super_classrefs_section];
-          /* APPLE LOCAL radar 5575115 */
-          else if (!strncmp (name, "l_objc_msgSend_", 15))
+          /* APPLE LOCAL radar 5575115 - radar 6252174 */
+          else if (!strncmp (name, "l_objc_msgSend", 14))
             return darwin_sections[objc_v2_message_refs_section];
           else if (!strncmp (name, "_OBJC_LABEL_CLASS_", 18))
             return darwin_sections[objc_v2_classlist_section];
@@ -1524,8 +1547,14 @@
             return darwin_sections[objc_v2_selector_refs_section];
           else if (!strncmp (name, "_OBJC_IMAGE_INFO", 16))
             return darwin_sections[objc_v2_image_info_section];
+	    /* APPLE LOCAL begin radar 6255595 */
+	  else if (!strncmp (name, "OBJC_CLASS_$_", 13)
+		   || !strncmp (name, "OBJC_METACLASS_$_", 17))
+	    return darwin_sections[objc_v2_classdefs_section];
           else
-            return base_section;
+            return  (base_section == data_section) ? 
+		      darwin_sections[objc_v2_metadata_section] : base_section;
+    	  /* APPLE LOCAL end radar 6255595 */
 	}
       /* APPLE LOCAL end radar 4792158 */
     }
@@ -2158,6 +2187,8 @@
 	  /* APPLE LOCAL begin pubtypes, approved for 4.3 4535968  */
 	  DEBUG_PUBTYPES_SECTION,
 	  /* APPLE LOCAL end pubtypes, approved for 4.3 4535968  */
+	  /* APPLE LOCAL radar 6275985 debug inlined section  */
+	  DEBUG_INLINED_SECTION,
 	  DEBUG_STR_SECTION,
 	  DEBUG_RANGES_SECTION
 	};

Modified: llvm-gcc-4.2/trunk/gcc/config/darwin.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/config/darwin.h?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/config/darwin.h (original)
+++ llvm-gcc-4.2/trunk/gcc/config/darwin.h Mon Nov  3 01:33:15 2008
@@ -156,7 +156,8 @@
   { "-seg_addr_table_filename", "-Zfn_seg_addr_table_filename" }, \
   /* APPLE LOCAL mainline */ \
   { "-umbrella", "-Zumbrella" }, \
-  { "-fapple-kext", "-fapple-kext -static -Wa,-static" }, \
+  /* APPLE LOCAL kext weak_import 5935650 */ \
+  { "-fapple-kext", "-fapple-kext -static" }, \
   { "-filelist", "-Xlinker -filelist -Xlinker" },  \
   { "-findirect-virtual-calls", "-fapple-kext" }, \
   { "-flat_namespace", "-Zflat_namespace" },  \
@@ -169,17 +170,20 @@
   { "-install_name", "-Zinstall_name" },  \
   /* LLVM LOCAL */ \
   LLVM_FLAG  \
-  { "-mkernel", "-mkernel -static -Wa,-static" }, \
+  /* APPLE LOCAL kext weak_import 5935650 */ \
+  { "-mkernel", "-mkernel -static" }, \
   { "-multiply_defined_unused", "-Zmultiplydefinedunused" },  \
   { "-multiply_defined", "-Zmultiply_defined" },  \
   { "-multi_module", "-Zmulti_module" },  \
-  { "-static", "-static -Wa,-static" },  \
+  /* APPLE LOCAL begin kext weak_import 5935650 */ \
+  /* Removed -static */ \
+  /* APPLE LOCAL end kext weak_import 5935650 */ \
   /* APPLE LOCAL mainline */ \
   { "-shared", "-Zdynamiclib" }, \
   { "-single_module", "-Zsingle_module" },  \
   { "-unexported_symbols_list", "-Zunexported_symbols_list" }, \
-  /* APPLE LOCAL ObjC GC */ \
-  { "-fobjc-gc", "-fobjc-gc -Wno-non-lvalue-assign" }, \
+  /* APPLE LOCAL radar 6269491 */ \
+  /* code removed. */ \
   /* APPLE LOCAL begin constant cfstrings */	\
   { "-fconstant-cfstrings", "-mconstant-cfstrings" }, \
   { "-fno-constant-cfstrings", "-mno-constant-cfstrings" }, \
@@ -576,11 +580,14 @@
 /* APPLE LOCAL end ARM 5683689 */
 
 /* Default Darwin ASM_SPEC, very simple.  */
+/* APPLE LOCAL begin kext weak_import 5935650 */
 /* APPLE LOCAL begin radar 4161346 */
 #define ASM_SPEC "-arch %(darwin_arch) \
   %{Zforce_cpusubtype_ALL:-force_cpusubtype_ALL} \
-  %{!Zforce_cpusubtype_ALL:%{faltivec:-force_cpusubtype_ALL}}"
+  %{!Zforce_cpusubtype_ALL:%{faltivec:-force_cpusubtype_ALL}} \
+  %{mkernel|static|fapple-kext:%{!Zdynamic:-static}}"
 /* APPLE LOCAL end radar 4161346 */
+/* APPLE LOCAL end kext weak_import 5935650 */
 /* APPLE LOCAL begin mainline 4.3 2006-10-31 4370143 */
 /* We still allow output of STABS.  */
 
@@ -614,6 +621,8 @@
 /* APPLE LOCAL begin pubtypes, approved for 4.3  4535968 */
 #define DEBUG_PUBTYPES_SECTION  "__DWARF,__debug_pubtypes,regular,debug"
 /* APPLE LOCAL end pubtypes, approved for 4.3 4535968 */
+/* APPLE LOCAL radar 6275985 debug inlined section */
+#define DEBUG_INLINED_SECTION   "__DWARF,__debug_inlined,regular,debug"
 #define DEBUG_STR_SECTION	"__DWARF,__debug_str,regular,debug"
 #define DEBUG_RANGES_SECTION	"__DWARF,__debug_ranges,regular,debug"
 
@@ -858,6 +867,13 @@
   } while (0)
 /* APPLE LOCAL end radar 4531086 */
 
+/* APPLE LOCAL begin radar 6307941 */
+#undef OBJC2_ABI_DISPATCH
+#define OBJC2_ABI_DISPATCH						\
+(darwin_macosx_version_min						\
+ && strverscmp (darwin_macosx_version_min, "10.6") < 0)
+/* APPLE LOCAL end radar 6307941 */
+
 /* The RTTI data (e.g., __ti4name) is common and public (and static),
    but it does need to be referenced via indirect PIC data pointers.
    The machopic_define_symbol calls are telling the machopic subsystem
@@ -1238,7 +1254,8 @@
 
 #undef ASM_PREFERRED_EH_DATA_FORMAT
 #define ASM_PREFERRED_EH_DATA_FORMAT(CODE,GLOBAL)  \
-  (((CODE) == 2 && (GLOBAL) == 1) \
+  /* APPLE LOCAL EH __TEXT __gcc_except_tab 5819051 */	      \
+  ((((CODE) == 2 || (CODE) == 0) && (GLOBAL) == 1)	      \
    ? (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4) : \
      ((CODE) == 1 || (GLOBAL) == 0) ? DW_EH_PE_pcrel : DW_EH_PE_absptr)
 

Modified: llvm-gcc-4.2/trunk/gcc/config/i386/i386.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/config/i386/i386.c?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/config/i386/i386.c (original)
+++ llvm-gcc-4.2/trunk/gcc/config/i386/i386.c Mon Nov  3 01:33:15 2008
@@ -6880,6 +6880,20 @@
 	  /* TLS references should always be enclosed in UNSPEC.  */
 	  if (SYMBOL_REF_TLS_MODEL (op0))
 	    return false;
+	  /* APPLE LOCAL begin 6227434 */
+#if TARGET_MACHO
+	  /* ObjC machinery always has a legitimate PIC
+	     address.  */
+	  if (objc_anonymous_local_objc_name (XSTR (op0, 0))
+	      || SYMBOL_REF_LOCAL_P (op0))
+	    return true;
+	  /* Under -mfix-and-continue, even local storage is
+	     addressed via the GOT, so that the value of local
+	     statics is preserved when a function is "fixed."  */
+	  if (TARGET_FIX_AND_CONTINUE)
+	    return false;
+#endif
+	  /* APPLE LOCAL end 6227434 */
 	  if (!SYMBOL_REF_FAR_ADDR_P (op0) && SYMBOL_REF_LOCAL_P (op0))
 	    return true;
 	  break;
@@ -9615,10 +9629,7 @@
 {
   int strict = (reload_in_progress || reload_completed);
   /* APPLE LOCAL dynamic-no-pic */
-#if TARGET_MACHO
-  rtx insn;
-#endif
-  rtx op0, op1;
+  rtx insn, op0, op1;
   enum tls_model model;
 
   op0 = operands[0];
@@ -15923,14 +15934,14 @@
   /* SSE4.1 */
   { MASK_SSE4_1, CODE_FOR_sse4_1_packusdw, "__builtin_ia32_packusdw128", IX86_BUILTIN_PACKUSDW128, UNKNOWN, 0 },
   { MASK_SSE4_1, CODE_FOR_sse4_1_eqv2di3, "__builtin_ia32_pcmpeqq", IX86_BUILTIN_PCMPEQQ, UNKNOWN, 0 },
-  { MASK_SSE4_1, CODE_FOR_smaxv16qi3, "__builtin_ia32_pmaxsb128", IX86_BUILTIN_PMAXSB128, UNKNOWN, 0 },
-  { MASK_SSE4_1, CODE_FOR_smaxv4si3, "__builtin_ia32_pmaxsd128", IX86_BUILTIN_PMAXSD128, UNKNOWN, 0 },
-  { MASK_SSE4_1, CODE_FOR_umaxv4si3, "__builtin_ia32_pmaxud128", IX86_BUILTIN_PMAXUD128, UNKNOWN, 0 },
-  { MASK_SSE4_1, CODE_FOR_umaxv8hi3, "__builtin_ia32_pmaxuw128", IX86_BUILTIN_PMAXUW128, UNKNOWN, 0 },
-  { MASK_SSE4_1, CODE_FOR_sminv16qi3, "__builtin_ia32_pminsb128", IX86_BUILTIN_PMINSB128, UNKNOWN, 0 },
-  { MASK_SSE4_1, CODE_FOR_sminv4si3, "__builtin_ia32_pminsd128", IX86_BUILTIN_PMINSD128, UNKNOWN, 0 },
-  { MASK_SSE4_1, CODE_FOR_uminv4si3, "__builtin_ia32_pminud128", IX86_BUILTIN_PMINUD128, UNKNOWN, 0 },
-  { MASK_SSE4_1, CODE_FOR_uminv8hi3, "__builtin_ia32_pminuw128", IX86_BUILTIN_PMINUW128, UNKNOWN, 0 },
+  { MASK_SSE4_1, CODE_FOR_sse4_1_smaxv16qi3, "__builtin_ia32_pmaxsb128", IX86_BUILTIN_PMAXSB128, UNKNOWN, 0 },
+  { MASK_SSE4_1, CODE_FOR_sse4_1_smaxv4si3, "__builtin_ia32_pmaxsd128", IX86_BUILTIN_PMAXSD128, UNKNOWN, 0 },
+  { MASK_SSE4_1, CODE_FOR_sse4_1_umaxv4si3, "__builtin_ia32_pmaxud128", IX86_BUILTIN_PMAXUD128, UNKNOWN, 0 },
+  { MASK_SSE4_1, CODE_FOR_sse4_1_umaxv8hi3, "__builtin_ia32_pmaxuw128", IX86_BUILTIN_PMAXUW128, UNKNOWN, 0 },
+  { MASK_SSE4_1, CODE_FOR_sse4_1_sminv16qi3, "__builtin_ia32_pminsb128", IX86_BUILTIN_PMINSB128, UNKNOWN, 0 },
+  { MASK_SSE4_1, CODE_FOR_sse4_1_sminv4si3, "__builtin_ia32_pminsd128", IX86_BUILTIN_PMINSD128, UNKNOWN, 0 },
+  { MASK_SSE4_1, CODE_FOR_sse4_1_uminv4si3, "__builtin_ia32_pminud128", IX86_BUILTIN_PMINUD128, UNKNOWN, 0 },
+  { MASK_SSE4_1, CODE_FOR_sse4_1_uminv8hi3, "__builtin_ia32_pminuw128", IX86_BUILTIN_PMINUW128, UNKNOWN, 0 },
   { MASK_SSE4_1, CODE_FOR_sse4_1_mulv2siv2di3, 0, IX86_BUILTIN_PMULDQ128, UNKNOWN, 0 },
   { MASK_SSE4_1, CODE_FOR_mulv4si3, "__builtin_ia32_pmulld128", IX86_BUILTIN_PMULLD128, UNKNOWN, 0 },
 

Modified: llvm-gcc-4.2/trunk/gcc/coverage.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/coverage.c?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/coverage.c (original)
+++ llvm-gcc-4.2/trunk/gcc/coverage.c Mon Nov  3 01:33:15 2008
@@ -77,13 +77,15 @@
 static unsigned no_coverage = 0;
 
 /* Cumulative counter information for whole program.  */
-static unsigned prg_ctr_mask; /* Mask of counter types generated.  */
-static unsigned prg_n_ctrs[GCOV_COUNTERS]; /* Total counters allocated.  */
+/* APPLE LOCAL begin 5834718 */
+static GTY (()) unsigned prg_ctr_mask; /* Mask of counter types generated.  */
+static GTY (()) unsigned prg_n_ctrs[GCOV_COUNTERS]; /* Total counters allocated.  */
 
 /* Counter information for current function.  */
-static unsigned fn_ctr_mask; /* Mask of counters used.  */
-static unsigned fn_n_ctrs[GCOV_COUNTERS]; /* Counters allocated.  */
-static unsigned fn_b_ctrs[GCOV_COUNTERS]; /* Allocation base.  */
+static GTY (()) unsigned fn_ctr_mask; /* Mask of counters used.  */
+static GTY (()) unsigned fn_n_ctrs[GCOV_COUNTERS]; /* Counters allocated.  */
+static  GTY (()) unsigned fn_b_ctrs[GCOV_COUNTERS]; /* Allocation base.  */
+/* APPLE LOCAL end 5834718 */
 
 /* Name of the output file for coverage output file.  */
 static char *bbg_file_name;

Modified: llvm-gcc-4.2/trunk/gcc/cp/call.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/cp/call.c?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/cp/call.c (original)
+++ llvm-gcc-4.2/trunk/gcc/cp/call.c Mon Nov  3 01:33:15 2008
@@ -797,7 +797,8 @@
       /* Allow conversions among compatible ObjC pointer types (base
 	 conversions have been already handled above).  */
       else if (c_dialect_objc ()
-	       && objc_compare_types (to, from, -4, NULL_TREE))
+	       /* APPLE LOCAL radar 6231433 */
+	       && objc_compare_types (to, from, -4, NULL_TREE, NULL))
 	conv = build_conv (ck_ptr, to, conv);
       /* APPLE LOCAL end 4154928 */
       else if (ptr_reasonably_similar (to_pointee, from_pointee))

Modified: llvm-gcc-4.2/trunk/gcc/cp/decl.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/cp/decl.c?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/cp/decl.c (original)
+++ llvm-gcc-4.2/trunk/gcc/cp/decl.c Mon Nov  3 01:33:15 2008
@@ -2465,39 +2465,6 @@
   return check_previous_goto_1 (NULL_TREE, level, level->names, false, NULL);
 }
 
-/* APPLE LOCAL begin blocks 6040305 (cp) */
-/* This routine issues a diagnostic if a __block variable is seen in
-   the current scope.  This is for now called from a goto statement.  */
-void
-diagnose_byref_var_in_current_scope (void)
-{
-#if 0
-  /* FIXME finish this off. */
-  struct c_scope *scope;
-  struct c_binding *b;
-
-  gcc_assert (current_scope);
-  if (flag_objc_gc_only || !current_scope->byref_in_current_scope)
-    return;
-
-  scope = current_scope;
-  while (scope && scope != file_scope)
-  {
-    for (b = scope->bindings; b; b = b->prev)
-    {
-      tree p = b->decl;
-      if (p && TREE_CODE (p) == VAR_DECL && COPYABLE_BYREF_LOCAL_VAR (p)) {
-        error ("local byref variable %s is in the scope of this goto",
-               IDENTIFIER_POINTER (DECL_NAME (p)));
-        return;
-      }
-    }
-    scope = scope->outer;
-  }
-#endif
-}
-/* APPLE LOCAL end blocks 6040305 (cp) */
-
 /* Check that a new jump to a label DECL is OK.  Called by
    finish_goto_stmt.  */
 
@@ -2508,10 +2475,6 @@
   bool saw_catch = false, identified = false;
   tree bad;
 
-  /* APPLE LOCAL begin 6040305 */
-  diagnose_byref_var_in_current_scope ();
-  /* APPLE LOCAL end 6040305 */
-
   /* We can't know where a computed goto is jumping.
      So we assume that it's OK.  */
   if (TREE_CODE (decl) != LABEL_DECL)
@@ -5494,12 +5457,12 @@
 
   struct __Block_byref_x {
     // APPLE LOCAL radar 6244520
-    void *isa;			// NULL for everything except __weak pointers
-    struct Block_byref_x *forwarding;
-    int32_t flags;
-    int32_t size;
-    void *ByrefKeepFuncPtr;    // Only if variable is __byref ObjC object
-    void *ByrefDestroyFuncPtr; // Only if variable is __byref ObjC object
+    void *__isa;			// NULL for everything except __weak pointers
+    struct Block_byref_x *__forwarding;
+    int32_t __flags;
+    int32_t __size;
+    void *__ByrefKeepFuncPtr;    // Only if variable is __block ObjC object
+    void *__ByrefDestroyFuncPtr; // Only if variable is __block ObjC object
     typex x;
   } x;
 */
@@ -5523,36 +5486,36 @@
   Block_byref_type = block_start_struct (get_identifier (string));
   
   /* APPLE LOCAL begin radar 6244520 */
-  /* void *isa; */
-  field = build_decl (FIELD_DECL, get_identifier ("isa"), ptr_type_node);
+  /* void *__isa; */
+  field = build_decl (FIELD_DECL, get_identifier ("__isa"), ptr_type_node);
   fields = field;
   /* APPLE LOCAL end radar 6244520 */  
 
-  /* struct Block_byref_x *forwarding; */
-  field = build_decl (FIELD_DECL, get_identifier ("forwarding"),
+  /* struct Block_byref_x *__forwarding; */
+  field = build_decl (FIELD_DECL, get_identifier ("__forwarding"),
                       build_pointer_type (Block_byref_type));
   /* APPLE LOCAL radar 6244520 */
   chainon (fields, field);
 
-  /* int32_t flags; */
-  field = build_decl (FIELD_DECL, get_identifier ("flags"),
+  /* int32_t __flags; */
+  field = build_decl (FIELD_DECL, get_identifier ("__flags"),
                       unsigned_type_node);
   chainon (fields, field);
 
-  /* int32_t size; */
-  field = build_decl (FIELD_DECL, get_identifier ("size"),
+  /* int32_t __size; */
+  field = build_decl (FIELD_DECL, get_identifier ("__size"),
                       unsigned_type_node);
   chainon (fields, field);
 
   if (COPYABLE_BYREF_LOCAL_NONPOD (decl))
   {
-    /* void *ByrefKeepFuncPtr; */
-    field = build_decl (FIELD_DECL, get_identifier ("ByrefKeepFuncPtr"),
+    /* void *__ByrefKeepFuncPtr; */
+    field = build_decl (FIELD_DECL, get_identifier ("__ByrefKeepFuncPtr"),
                         ptr_type_node);
     chainon (fields, field);
 
-    /* void *ByrefDestroyFuncPtr; */
-    field = build_decl (FIELD_DECL, get_identifier ("ByrefDestroyFuncPtr"),
+    /* void *__ByrefDestroyFuncPtr; */
+    field = build_decl (FIELD_DECL, get_identifier ("__ByrefDestroyFuncPtr"),
                         ptr_type_node);
     chainon (fields, field);
   }
@@ -5580,7 +5543,7 @@
    { NULL, &x, 0, sizeof(struct __Block_byref_x)};
    when INIT is NULL_TREE
 
-   For __byref ObjC objects, it also adds "byref_keep" and "byref_destroy"
+   For __block ObjC objects, it also adds "byref_keep" and "byref_destroy"
    Funtion pointers. So the most general initializers would be:
 
    { NULL, &x, 0, sizeof(struct __Block_byref_x), &byref_keep, &byref_destroy,
@@ -5817,7 +5780,7 @@
         if (DECL_EXTERNAL (decl) || TREE_STATIC (decl))
         {
 	    warning (0,
-		     "__byref attribute is only allowed on local variables - ignored");
+		     "__block attribute is only allowed on local variables - ignored");
 	    COPYABLE_BYREF_LOCAL_VAR (decl) = 0;
 	    COPYABLE_BYREF_LOCAL_NONPOD (decl) = 0;
 	  }
@@ -11554,6 +11517,82 @@
 }
 
 
+/* APPLE LOCAL begin warn missing prototype 6261539 */
+static bool
+fn_previously_found (tree decl, tree olddecl)
+{
+  int types_match;
+
+  if (olddecl == 0)
+    return false;
+
+  if (TREE_CODE (olddecl) == OVERLOAD)
+    {
+      if (OVL_CHAIN (olddecl) == NULL_TREE)
+	olddecl = OVL_CURRENT (olddecl);
+      else
+	{
+	  tree match;
+	  for (match = olddecl; match; match = OVL_NEXT (match))
+	    {
+	      if (fn_previously_found (decl, OVL_CURRENT (match)))
+		return true;
+	    }
+	  return false;
+	}
+    }	  
+
+  /* Don't warn about previously erroneous things that have the same
+     name.  */
+  if (TREE_TYPE (olddecl) == error_mark_node)
+    return true;
+
+  /* Internally defined things still need a prototype to escape the
+     warning.  */
+  if (DECL_ARTIFICIAL (olddecl))
+    return false;
+
+  if (TREE_CODE (olddecl) != FUNCTION_DECL)
+    return false;
+
+  /* These will match or error, don't also spew prototype warnings.  */
+  if (DECL_EXTERN_C_P (olddecl)
+      && DECL_EXTERN_C_P (decl))
+    return true;
+
+  /* These will match or error, don't also spew prototype warnings.  */
+  if (compparms (TYPE_ARG_TYPES (TREE_TYPE (decl)),
+		 TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
+    return true;
+
+  types_match = decls_match (decl, olddecl);
+    
+  if (types_match)
+    return true;
+
+  return false;
+}
+
+inline static void
+check_missing_prototype (tree decl)
+{
+  if (warn_missing_prototypes
+      && namespace_bindings_p ()
+      && TREE_PUBLIC (decl)
+      && !DECL_MAIN_P (decl)
+      && DECL_NON_THUNK_FUNCTION_P (decl)
+      && ! DECL_FUNCTION_MEMBER_P (decl)
+      && DECL_NAMESPACE_SCOPE_P (decl)
+      && ! decl_anon_ns_mem_p (decl)
+      && ! DECL_DECLARED_INLINE_P (decl))
+    {
+      tree olddecl = namespace_binding (DECL_NAME (decl),  DECL_CONTEXT (decl));
+      if (!fn_previously_found (decl, olddecl))
+	warning (OPT_Wmissing_prototypes, "no previous prototype for %q+D", decl);
+    }
+}
+/* APPLE LOCAL end warn missing prototype 6261539 */
+
 /* Like start_preparsed_function, except that instead of a
    FUNCTION_DECL, this function takes DECLSPECS and DECLARATOR.
 
@@ -11586,6 +11625,10 @@
     gcc_assert (same_type_p (TREE_TYPE (TREE_TYPE (decl1)),
 			     integer_type_node));
 
+  /* APPLE LOCAL begin warn missing prototype 6261539 */
+  check_missing_prototype (decl1);
+  /* APPLE LOCAL end warn missing prototype 6261539 */
+
   start_preparsed_function (decl1, attrs, /*flags=*/SF_DEFAULT);
 
   return 1;

Modified: llvm-gcc-4.2/trunk/gcc/cp/name-lookup.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/cp/name-lookup.c?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/cp/name-lookup.c (original)
+++ llvm-gcc-4.2/trunk/gcc/cp/name-lookup.c Mon Nov  3 01:33:15 2008
@@ -4039,12 +4039,12 @@
 
 	if (binding)
 	  {
-            /* APPLE LOCAL begin 6322334 */
-            /* Ick, we don't want to find a hidden friend inside a
-               local class!  */
-            if (hidden_name_p (binding))
-              POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
-            /* APPLE LOCAL end 6322334 */
+	    /* APPLE LOCAL begin 6322334 */
+	    /* Ick, we don't want to find a hidden friend inside a
+	       local class!  */ 
+	    if (hidden_name_p (binding))
+	      POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
+	    /* APPLE LOCAL end 6322334 */
 
 	    val = binding;
 	    break;

Modified: llvm-gcc-4.2/trunk/gcc/cp/parser.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/cp/parser.c?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/cp/parser.c (original)
+++ llvm-gcc-4.2/trunk/gcc/cp/parser.c Mon Nov  3 01:33:15 2008
@@ -2794,6 +2794,12 @@
 	      error ("unknown property attribute");
 	      break;
 	    }
+	  /* APPLE LOCAL begin radar 6302949 */
+	  if (cp_lexer_next_token_is_not (parser->lexer, CPP_COMMA)
+	      && cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN)
+	      && cp_lexer_next_token_is_not (parser->lexer, CPP_EOF))
+	    warning (0, "property attributes must be separated by a comma");
+	  /* APPLE LOCAL end radar 6302949 */
 	  if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
 	    cp_lexer_consume_token (parser->lexer);
 	  token = cp_lexer_peek_token (parser->lexer);	  
@@ -19451,6 +19457,15 @@
       if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN))
 	cp_type = cp_parser_type_id (parser);
 
+      /* APPLE LOCAL begin radar 6261630 */
+      if (cp_lexer_next_token_is_keyword (parser->lexer, RID_ATTRIBUTE))
+      {
+        /* Chain on the trailing attribute. */
+        tree attrs = chainon (NULL_TREE,
+                              cp_parser_attributes_opt (parser));
+        cplus_decl_attributes (&cp_type, attrs, 0);
+      }
+      /* APPLE LOCAL end radar 6261630 */
       cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
       typename = build_tree_list (proto_quals, cp_type);
     }
@@ -19753,8 +19768,8 @@
 	  /* APPLE LOCAL begin radar 4290840 */
 	  /* Check for all possibilities of illegal lookahead tokens. */
 	  ptk = cp_lexer_peek_token (parser->lexer);
-	  if (!(ptk->type == CPP_PLUS || ptk->type == CPP_MINUS 
-		|| ptk->type == CPP_EOF || ptk->keyword == RID_AT_END))
+	  /* APPLE LOCAL radar 6271728 */
+	  if (ptk->type == CPP_OPEN_BRACE)
 	    {
 	      perform_deferred_access_checks ();
 	      stop_deferring_access_checks ();
@@ -19763,6 +19778,10 @@
 	      pop_deferring_access_checks ();
 	      objc_finish_method_definition (meth);
 	    }
+	  /* APPLE LOCAL begin radar 6271728 */
+          else
+            cp_parser_require (parser, CPP_OPEN_BRACE, "`{'");
+	  /* APPLE LOCAL end radar 6271728 */
 	  /* APPLE LOCAL end radar 4290840 */
 	}
       /* APPLE LOCAL begin C* interface */
@@ -20519,18 +20538,175 @@
 }
 /* APPLE LOCAL end radar 6214617 */
 
-static tree block_copy_assign_decl;
-static tree block_destroy_decl;
+/* APPLE LOCAL begin radar 6175959 */
+static GTY(()) tree block_copy_assign_decl;
+static GTY(()) tree block_object_assign_decl;
+static GTY(()) tree block_destroy_decl;
+static GTY(()) tree block_object_dispose_func_decl;
+/* APPLE LOCAL end radar 6175959 */
+
+/* APPLE LOCAL begin radar 5847213 - radar 6329245 */
+/** build_descriptor_block_decl -
+  This routine builds a static block_descriptior variable of type:
+  struct __block_descriptor; and initializes it to:
+  {0, sizeof(struct literal_block_n), 
+   copy_helper_block_1, // only if block BLOCK_HAS_COPY_DISPOSE
+   destroy_helper_block_1, // only if block BLOCK_HAS_COPY_DISPOSE
+  }
+*/
+static tree
+build_descriptor_block_decl (tree block_struct_type, struct block_sema_info *block_impl)
+{
+  extern tree create_tmp_var_raw (tree, const char *);
+  static int desc_unique_count;
+  int size;
+  tree helper_addr;
+  tree decl, constructor;
+  char name [32];
+  VEC(constructor_elt,gc) *impl_v = NULL;
+  tree descriptor_type =  
+    TREE_TYPE (build_block_descriptor_type (block_impl->BlockHasCopyDispose));
+
+  sprintf (name, "__block_descriptor_tmp_%d", ++desc_unique_count);
+  decl = create_tmp_var_raw (descriptor_type, name);
+  DECL_CONTEXT (decl) = NULL_TREE;
+
+  /* Initialize "reserved" field to 0 for now. */
+  CONSTRUCTOR_APPEND_ELT(impl_v, NULL_TREE, build_int_cst (long_unsigned_type_node, 0));
+  
+  /* Initialize "Size" field. */
+  size = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (block_struct_type));
+  CONSTRUCTOR_APPEND_ELT(impl_v, NULL_TREE, build_int_cst (long_unsigned_type_node, size));
+
+  if (block_impl->BlockHasCopyDispose)
+    {
+      /* Initialize "CopyFuncPtr" and "DestroyFuncPtr" fields. */
+      /* Helpers were previously generated completeley as a nested
+	 function (and context was required for code gen.) But they are not, 
+	 so context must be set to NULL so initialization logic does not complain. */
+      DECL_CONTEXT (block_impl->copy_helper_func_decl) = NULL_TREE;
+      helper_addr = build_fold_addr_expr (block_impl->copy_helper_func_decl);
+      helper_addr = convert (ptr_type_node, helper_addr);
+      CONSTRUCTOR_APPEND_ELT(impl_v, NULL_TREE, helper_addr);
+
+      DECL_CONTEXT (block_impl->destroy_helper_func_decl) = NULL_TREE;
+      helper_addr = build_fold_addr_expr (block_impl->destroy_helper_func_decl);
+      helper_addr = convert (ptr_type_node, helper_addr);
+      CONSTRUCTOR_APPEND_ELT(impl_v, NULL_TREE, helper_addr);
+    }
+  /* Create a CONSTRUCTOR to represent the braced-initializer.  */
+  constructor = make_node (CONSTRUCTOR);
+  CONSTRUCTOR_ELTS (constructor) = impl_v;
+  TREE_PUBLIC (decl) = 0;
+  TREE_STATIC (decl) = 1;
+  cp_finish_decl (decl, constructor, 0, 0, LOOKUP_ONLYCONVERTING);
+  return decl;
+}
+
+/* APPLE LOCAL begin radar 6300081  */
+/* This function builds a "generic" block struct type, to be passed 
+   into the debug information for blocks pointers, to allow gdb to
+   find the actual function pointer for the block.  Any time the Blocks
+   structure layout changes, this may also need to change.
+
+   Currently a block pointer is a pointer to a __block_literal_n struct,
+   the third field of which is a pointer to a __block_descriptor struct,
+   whose third field is the function pointer.  There are other fields as
+   well, but these are the ones gdb needs to know about to find the
+   function pointer.  Therefore a generic block struct currently looks
+   like this:
+
+   struct __block_literal_generic 
+   {
+      void * __isa;
+      int __flags;
+      int __reserved;
+      void *__FuncPtr;
+      struct __block_descriptor 
+        {
+          unsigned long int reserved;
+	  unsigned long int Size;
+	} *__descriptor;
+   };
+
+   IF AT ANY TIME THE STRUCTURE OF A __BLOCK_LITERAL_N CHANGES, THIS
+   MUST BE CHANGED ALSO!!
+
+*/
+
+tree
+build_generic_block_struct_type (void)
+{
+  tree fields = NULL_TREE;
+  tree field;
+  tree block_struct_type;
+
+  push_to_top_level ();
+  block_struct_type = xref_tag (record_type, 
+				get_identifier ("__block_literal_generic"), 
+				ts_current, false);
+  xref_basetypes (block_struct_type, NULL_TREE);
+  CLASSTYPE_DECLARED_CLASS (block_struct_type) = 0;
+  pushclass (block_struct_type);
+
+  field = build_decl (FIELD_DECL, get_identifier ("__isa"), ptr_type_node);
+  TREE_CHAIN (field) = fields;
+  fields = field;
+
+  field = build_decl (FIELD_DECL, get_identifier ("__flags"), 
+		      integer_type_node);
+  TREE_CHAIN (field) = fields;
+  fields = field;
+
+  field = build_decl (FIELD_DECL, get_identifier ("__reserved"), 
+		      integer_type_node);
+  TREE_CHAIN (field) = fields;
+  fields = field;
+
+  field = build_decl (FIELD_DECL, get_identifier ("__FuncPtr"), 
+		      ptr_type_node);
+  TREE_CHAIN (field) = fields;
+  fields = field;
+
+  field = build_decl (FIELD_DECL, get_identifier ("__descriptor"),
+		      build_block_descriptor_type (false));
+  TREE_CHAIN (field) = fields;
+  fields = field;
+
+  TYPE_FIELDS (block_struct_type) = fields;
+  TYPE_NAME (block_struct_type) = build_decl (TYPE_DECL, 
+					      get_identifier ("__block_literal_generic"), 
+					      block_struct_type);
+  TYPE_STUB_DECL (block_struct_type) = TYPE_NAME (block_struct_type);
+  TYPE_BLOCK_IMPL_STRUCT (block_struct_type) = 1;
+  finish_struct (block_struct_type, NULL_TREE);
+  pop_from_top_level ();
+
+  return block_struct_type;
+}
+/* APPLE LOCAL end radar 6300081  */
 
 /** build_block_struct_type -
- struct block_1 {
- struct invok_impl impl;
- void *CopyFuncPtr;   // only if BLOCK_HAS_COPY_DISPOSE is set
- void *DestroyFuncPtr;  // only if BLOCK_HAS_COPY_DISPOSE is set
+ struct __block_literal_n {
+  void *__isa; // initialized to &_NSConcreteStackBlock or &_NSConcreteGlobalBlock
+  int __flags;
+  int __reserved;
+  void *__FuncPtr;
+
+  struct __block_descriptor {
+    unsigned long int reserved;     // NULL
+    unsigned long int Size;  // sizeof(struct __block_literal_n)
+
+    // optional helper functions
+    void *CopyFuncPtr; // When BLOCK_HAS_COPY_DISPOSE
+    void *DestroyFuncPtr; // When BLOCK_HAS_COPY_DISPOSE
+ } *__descriptor;
+
+ // imported variables
  int x; // ref variable list ...
  int *y; // byref variable list
  };
- */
+*/
 static tree
 build_block_struct_type (struct block_sema_info * block_impl)
 {
@@ -20538,9 +20714,6 @@
   char buffer[32];
   static int unique_count;
   tree block_struct_type;
-  /* build struct invok_impl */
-  if (!invoke_impl_ptr_type)
-    build_block_internal_types ();
 
   /* Check and see if this block is required to have a Copy/Dispose
      helper function. If yes, set BlockHasCopyDispose to TRUE. */
@@ -20559,7 +20732,7 @@
     /* APPLE LOCAL end radar 6214617 */
     }
 
-  /* Further check to see that we have __byref variables which require
+  /* Further check to see that we have __block variables which require
      Copy/Dispose helpers. */
   for (chain = block_impl->block_byref_decl_list; chain;
        chain = TREE_CHAIN (chain))
@@ -20569,29 +20742,43 @@
 	break;
       }
 
-  sprintf(buffer, "__block_%d", ++unique_count);
+  sprintf(buffer, "__block_literal_%d", ++unique_count);
   push_to_top_level ();
-  /* block_struct_type = start_struct (RECORD_TYPE, get_identifier (buffer)); */
-  block_struct_type = make_aggr_type (RECORD_TYPE);
+  /* APPLE LOCAL begin radar 6243400 */
+  block_struct_type = xref_tag (record_type, get_identifier (buffer), ts_current, false);
   xref_basetypes (block_struct_type, NULL_TREE);
+  CLASSTYPE_DECLARED_CLASS (block_struct_type) = 0;
+  pushclass (block_struct_type);
+  /* APPLE LOCAL end radar 6243400 */
+  /* void * __isa; */
+  field = build_decl (FIELD_DECL, get_identifier ("__isa"), ptr_type_node);
+  TREE_CHAIN (field) = fields;
+  fields = field;
+
+  /* int __flags. */
+  field = build_decl (FIELD_DECL, get_identifier ("__flags"), integer_type_node);
+  TREE_CHAIN (field) = fields;
+  fields = field;
+
+  /* int __reserved. */
+  field = build_decl (FIELD_DECL, get_identifier ("__reserved"), integer_type_node);
+  TREE_CHAIN (field) = fields;
+  fields = field;
 
-  /* struct invok_impl impl; */
-  field = build_decl (FIELD_DECL, get_identifier ("impl"),
-		      TREE_TYPE (invoke_impl_ptr_type));
+  /* void *__FuncPtr. */
+  field = build_decl (FIELD_DECL, get_identifier ("__FuncPtr"), 
+		      ptr_type_node);
   TREE_CHAIN (field) = fields;
   fields = field;
+
+  /* struct __block_descriptor *__descriptor */
+  field = build_decl (FIELD_DECL, get_identifier ("__descriptor"),
+                           build_block_descriptor_type (block_impl->BlockHasCopyDispose));
+  TREE_CHAIN (field) = fields;
+  fields = field;
+  
   if (block_impl->BlockHasCopyDispose)
   {
-    /* void *CopyFuncPtr; */
-    field = build_decl (FIELD_DECL, get_identifier ("CopyFuncPtr"),
-			ptr_type_node);
-    TREE_CHAIN (field) = fields;
-    fields = field;
-    /* void *DestroyFuncPtr; */
-    field = build_decl (FIELD_DECL, get_identifier ("DestroyFuncPtr"),
-			ptr_type_node);
-    TREE_CHAIN (field) = fields;
-    fields = field;
     /* If inner block of a nested block has BlockHasCopyDispose, so
        does its outer block. */
     if (block_impl->prev_block_info)
@@ -20622,33 +20809,27 @@
     fields = field;
   }
 
+  /* APPLE LOCAL begin radar 6243400 */
+  TYPE_FIELDS (block_struct_type) = fields;
+  TYPE_NAME (block_struct_type) = 
+    build_decl (TYPE_DECL, get_identifier (buffer), block_struct_type);
+  TYPE_STUB_DECL (block_struct_type) = TYPE_NAME (block_struct_type);
+  finish_struct (block_struct_type, NULL_TREE);
   pop_from_top_level ();
-  /* finish_struct (block_struct_type, field_decl_chain, NULL_TREE); */
-  finish_builtin_struct (block_struct_type, buffer,
-			 fields, NULL_TREE);
-  /* APPLE LOCAL begin radar 6169527 */
-  /* This type is now a full-blown c++ struct and as such, this field must
-     be set. */
-  CLASSTYPE_AS_BASE (block_struct_type) = block_struct_type;
-  /* APPLE LOCAL end radar 6169527 */
-  /* Zap out the name so that the back-end will give us the debugging
-     information for this anonymous RECORD_TYPE.  */
-  TYPE_NAME (block_struct_type) = NULL_TREE;
-
+  /* APPLE LOCAL end radar 6243400 */
   return block_struct_type;
 }
 
 /**
  build_block_struct_initlist - builds the initializer list:
- { &_NSConcreteStackBlock or &_NSConcreteGlobalBlock // isa,
-   BLOCK_HAS_CXX_OBJ | BLOCK_HAS_COPY_DISPOSE | BLOCK_IS_GLOBAL // flags,
-   sizeof(struct block_1),
-   helper_1 
- },
- copy_helper_block_1, // only if block BLOCK_HAS_COPY_DISPOSE
- destroy_helper_block_1, // only if block BLOCK_HAS_COPY_DISPOSE
- x,
- &y
+ { &_NSConcreteStackBlock or &_NSConcreteGlobalBlock // __isa,
+   BLOCK_HAS_DESCRIPTOR | BLOCK_HAS_COPY_DISPOSE | BLOCK_IS_GLOBAL // __flags,
+   0, // __reserved,
+   &helper_1, // __FuncPtr,
+   &static_descriptor_variable // __descriptor,
+   x, // user variables.
+   &y
+   ...
  }
 */
 /* APPLE LOCAL begin radar 6169527 */
@@ -20658,14 +20839,12 @@
 build_block_struct_initlist (tree block_struct_type,
 			     struct block_sema_info *block_impl)
 {
-  int size;
-  tree helper_addr, chain;
-  unsigned flags = 0;
+  tree expr, chain, helper_addr;
+  unsigned flags = BLOCK_HAS_DESCRIPTOR;
   static tree NSConcreteStackBlock_decl = NULL_TREE;
   static tree NSConcreteGlobalBlock_decl = NULL_TREE;
-  tree impl_constructor;
   VEC(constructor_elt,gc) *impl_v = NULL;
-  VEC(constructor_elt,gc) *v = NULL;
+  tree descriptor_block_decl = build_descriptor_block_decl (block_struct_type, block_impl);
 
   if (block_impl->BlockHasCopyDispose)
     /* Note! setting of this flag merely indicates to the runtime that
@@ -20677,8 +20856,11 @@
   if (block_impl->BlockImportsCxxObjects)
     flags |= BLOCK_HAS_CXX_OBJ;
   /* APPLE LOCAL end radar 6214617 */
-
-  if (!current_function_decl)
+  /* APPLE LOCAL begin radar 6230297 */
+  if (!current_function_decl ||
+      (block_impl->block_ref_decl_list == NULL_TREE &&
+       block_impl->block_byref_decl_list == NULL_TREE))
+  /* APPLE LOCAL end radar 6230297 */
     {
       /* This is a global block. */
       /* Find an existing declaration for _NSConcreteGlobalBlock or declare
@@ -20719,56 +20901,76 @@
       CONSTRUCTOR_APPEND_ELT(impl_v, NULL_TREE, build_fold_addr_expr (NSConcreteStackBlock_decl));
     }
 
-  CONSTRUCTOR_APPEND_ELT(impl_v, NULL_TREE, build_int_cst (unsigned_type_node, flags));
-  
-  size = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (block_struct_type));
-  CONSTRUCTOR_APPEND_ELT(impl_v, NULL_TREE, build_int_cst (unsigned_type_node, size));
-
+  /* __flags */
+  CONSTRUCTOR_APPEND_ELT(impl_v, NULL_TREE, build_int_cst (integer_type_node, flags));
+  /* __reserved */
+  CONSTRUCTOR_APPEND_ELT(impl_v, NULL_TREE, build_int_cst (integer_type_node, 0));
+  /* __FuncPtr */
   helper_addr = build_fold_addr_expr (block_impl->helper_func_decl);
-  /* mark_used (block_impl->helper_func_decl); */
   helper_addr = convert (ptr_type_node, helper_addr);
   CONSTRUCTOR_APPEND_ELT(impl_v, NULL_TREE, helper_addr);
-
-  impl_constructor = make_node (CONSTRUCTOR);
-  CONSTRUCTOR_ELTS (impl_constructor) = impl_v;
-  CONSTRUCTOR_APPEND_ELT(v, NULL_TREE, impl_constructor);
   
-  if (block_impl->BlockHasCopyDispose)
-    {
-      helper_addr = build_fold_addr_expr (block_impl->copy_helper_func_decl);
-      helper_addr = convert (ptr_type_node, helper_addr);
-      CONSTRUCTOR_APPEND_ELT(v, NULL_TREE, helper_addr);
-      helper_addr = build_fold_addr_expr (block_impl->destroy_helper_func_decl);
-      helper_addr = convert (ptr_type_node, helper_addr);
-      CONSTRUCTOR_APPEND_ELT(v, NULL_TREE, helper_addr);
-    }
+  /* &static_descriptor_variable initializer */
+  expr = build_fold_addr_expr (descriptor_block_decl);
+  CONSTRUCTOR_APPEND_ELT(impl_v, NULL_TREE, expr);
+
   for (chain = block_impl->block_original_ref_decl_list; chain;
        chain = TREE_CHAIN (chain))
     {
       tree y = TREE_VALUE (chain);
       TREE_USED (y) = 1;
-      CONSTRUCTOR_APPEND_ELT(v, NULL_TREE, copy_in_object (y));
+      CONSTRUCTOR_APPEND_ELT(impl_v, NULL_TREE, copy_in_object (y));
     }
-  for (chain = block_impl->block_original_byref_decl_list; chain;
+  for (chain = block_impl->block_byref_decl_list; chain;
        chain = TREE_CHAIN (chain))
     {
-      tree y = TREE_VALUE (chain);
+      tree y = lookup_name (DECL_NAME (TREE_VALUE (chain)));
+      tree forwarding_expr;
+      gcc_assert (y);
       TREE_USED (y) = 1;
-      y = build_fold_addr_expr (y);
-      CONSTRUCTOR_APPEND_ELT(v, NULL_TREE, y);
+      if (COPYABLE_BYREF_LOCAL_VAR (y))
+        {
+          /* For variables declared __block, either the original one
+             at the point of declaration or the imported version (which is
+             initialized in the helper function's prologue) is used to
+             initilize the byref variable field in the temporary. */
+          if (TREE_CODE (TREE_TYPE (y)) != RECORD_TYPE)
+            y = build_indirect_ref (y, "unary *");
+          /* We will be using the __block_struct_variable.__forwarding as the
+             initializer. */
+          forwarding_expr = build_component_ref (y, get_identifier ("__forwarding"));
+        }
+      else
+        /* Global variable is always assumed passed by its address. */
+        forwarding_expr = build_fold_addr_expr (y);
+
+      CONSTRUCTOR_APPEND_ELT(impl_v, NULL_TREE, forwarding_expr);
     }
-  return v;
+  return impl_v;
 }
 /* APPLE LOCAL end radar 6169527 */
+/* APPLE LOCAL end radar 5847213 - radar 6329245 */
 
 /**
  build_block_literal_tmp - This routine:
 
  1) builds block type:
- struct block_1 {
- struct invok_impl impl;
- void *CopyFuncPtr;    // only if block BLOCK_HAS_COPY_DISPOSE
- void *DestroyFuncPtr; // only if block BLOCK_HAS_COPY_DISPOSE
+ struct __block_literal_n {
+  void *__isa; // initialized to &_NSConcreteStackBlock or &_NSConcreteGlobalBlock
+  int __flags;
+  int __reserved;
+  void *__FuncPtr;
+
+  struct __block_descriptor {
+    unsigned long int reserved;     // NULL
+    unsigned long int Size;  // sizeof(struct Block_literal_1)
+
+    // optional helper functions
+    void *CopyFuncPtr; // When BLOCK_HAS_COPY_DISPOSE
+    void *DestroyFuncPtr; // When BLOCK_HAS_COPY_DISPOSE
+ } *__descriptor;
+
+ // imported variables
  int x; // ref variable list ...
  int *y; // byref variable list
  };
@@ -20780,10 +20982,14 @@
  struct block_1 I = {
  { &_NSConcreteStackBlock or &_NSConcreteGlobalBlock // isa,
    BLOCK_HAS_CXX_OBJ | BLOCK_HAS_COPY_DISPOSE | BLOCK_IS_GLOBAL // flags,
-   sizeof(struct block_1),
-   helper_1 },
- copy_helper_block_1, // only if block BLOCK_HAS_COPY_DISPOSE
- destroy_helper_block_1, // only if block BLOCK_HAS_COPY_DISPOSE
+   0, // reserved,
+   &helper_1,
+   &{
+      NULL,
+      sizeof(struct block_1),
+      copy_helper_block_1, // only if block BLOCK_HAS_COPY_DISPOSE
+      destroy_helper_block_1, // only if block BLOCK_HAS_COPY_DISPOSE
+    },
  x,
  &y
 };
@@ -20799,13 +21005,19 @@
   tree block_holder_tmp_decl;
   tree constructor;
   tree block_struct_type = TREE_TYPE (block_impl->block_arg_ptr_type);
-
+  /* APPLE LOCAL begin radar 6230297 */
+  bool staticBlockTmp = (block_impl->block_ref_decl_list == NULL_TREE &&
+                         block_impl->block_byref_decl_list == NULL_TREE);
 
   block_holder_tmp_decl = create_tmp_var_raw (block_struct_type, name);
   /* Context will not be known until when the literal is synthesized.
      This is more so in the case of nested block literal blocks.  */
   maybe_push_decl (block_holder_tmp_decl);
-  DECL_CONTEXT (block_holder_tmp_decl) = current_function_decl;
+  DECL_CONTEXT (block_holder_tmp_decl) = staticBlockTmp ? NULL_TREE
+                                                        : current_function_decl;
+  if (staticBlockTmp)
+    DECL_CONTEXT (block_impl->helper_func_decl) = NULL_TREE;
+  /* APPLE LOCAL end radar 6230297 */
   DECL_ARTIFICIAL (block_holder_tmp_decl) = 1;
 
   /* Create a CONSTRUCTOR to represent the braced-initializer.  */
@@ -20814,7 +21026,8 @@
   CONSTRUCTOR_ELTS (constructor) = build_block_struct_initlist (block_struct_type,
                                                                 block_impl);
   /* Temporary representing a global block is made global static.  */
-  if (global_bindings_p ()) {
+  /* APPLE LOCAL radar 6230297 */
+  if (staticBlockTmp || global_bindings_p ()) {
     TREE_PUBLIC (block_holder_tmp_decl) = 0;
     TREE_STATIC (block_holder_tmp_decl) = 1;
   }
@@ -20851,7 +21064,7 @@
   DECL_ARG_TYPE (dst_arg) = block_impl->block_arg_ptr_type;
   src_arg = build_decl (PARM_DECL, get_identifier ("_src"),
                         block_impl->block_arg_ptr_type);
-  DECL_CONTEXT (dst_arg) = cur_block->copy_helper_func_decl;
+  DECL_CONTEXT (src_arg) = cur_block->copy_helper_func_decl;
   TREE_USED (src_arg) = 1;
   DECL_ARG_TYPE (src_arg) = block_impl->block_arg_ptr_type;
   /* arg_info = xcalloc (1, sizeof (struct c_arg_info)); */
@@ -20879,6 +21092,8 @@
     /* APPLE LOCAL radar 6214617 */
     if (cp_block_requires_copying (TREE_VALUE (chain)))
     {
+      /* APPLE LOCAL begin radar 6175959 */
+      tree which_function_decl = NULL_TREE;
       tree p = TREE_VALUE (chain);
       tree dst_block_component, src_block_component;
       dst_block_component = build_component_ref (build_indirect_ref (dst_arg, "->"),
@@ -20888,27 +21103,25 @@
 
       if (TREE_CODE (TREE_TYPE (p)) == BLOCK_POINTER_TYPE)
       {
-        tree func_params, call_exp;
-        /* _Block_copy_assign(&_dest->myImportedBlock, _src->myImportedClosure) */
-        /* Build a: void _Block_copy_assign (void *, void *) if not done
+        /* _Block_copy_assign(&_dest->myImportedBlock, _src->myImportedClosure, 0) */
+        /* Build a: void _Block_copy_assign (void *, void *, int) if not done
            already. */
-        if (!block_copy_assign_decl)
+        /* APPLE LOCAL begin radar 6310599 */
+        if (!block_copy_assign_decl &&
+            !(block_copy_assign_decl = lookup_name (get_identifier ("_Block_copy_assign"))))
+        /* APPLE LOCAL end radar 6310599 */
         {
           tree func_type =
             build_function_type (void_type_node,
               tree_cons (NULL_TREE, ptr_type_node,
-                         tree_cons (NULL_TREE, ptr_type_node, void_list_node)));
+                         tree_cons (NULL_TREE, ptr_type_node,
+                                    tree_cons (NULL_TREE, integer_type_node, void_list_node))));
 
           block_copy_assign_decl = builtin_function ("_Block_copy_assign", func_type,
-						     0, NOT_BUILT_IN, 0, NULL_TREE);
+                                                     0, NOT_BUILT_IN, 0, NULL_TREE);
           TREE_NOTHROW (block_copy_assign_decl) = 0;
         }
-        dst_block_component = build_fold_addr_expr (dst_block_component);
-        func_params = tree_cons (NULL_TREE, dst_block_component,
-                                 tree_cons (NULL_TREE, src_block_component,
-                                            NULL_TREE));
-        call_exp = build_function_call (block_copy_assign_decl, func_params);
-        add_stmt (call_exp);
+        which_function_decl = block_copy_assign_decl;
       }
       /* APPLE LOCAL begin radar 6214617 */
       else if (TYPE_HAS_CONSTRUCTOR (TREE_TYPE (p)) 
@@ -20921,14 +21134,38 @@
       /* APPLE LOCAL end radar 6214617 */
       else
       {
-        /* _dest-> imported_object_x = [_src->imported_object_x retain] */
-        tree rhs, store;
-        /* [_src->imported_object_x retain] */
-        rhs = retain_block_component (src_block_component);
-        store = build_modify_expr (dst_block_component, NOP_EXPR, rhs);
-        add_stmt (store);
+        /* _Block_object_assign(&_dest->myImportedBlock, _src->myImportedClosure, 0) */
+        /* Build a: void _Block_object_assign (void *, void *, int) if not done
+           already. */
+        if (!block_object_assign_decl &&
+            !(block_object_assign_decl = lookup_name (get_identifier ("_Block_object_assign"))))
+        {
+          tree func_type =
+            build_function_type (void_type_node,
+              tree_cons (NULL_TREE, ptr_type_node,
+                         tree_cons (NULL_TREE, ptr_type_node,
+                                    tree_cons (NULL_TREE, integer_type_node, void_list_node))));
+
+          block_object_assign_decl = builtin_function ("_Block_object_assign", func_type,
+                                                     0, NOT_BUILT_IN, 0, NULL_TREE);
+          TREE_NOTHROW (block_object_assign_decl) = 0;
       }
+      which_function_decl = block_object_assign_decl;
+    }
+    if (which_function_decl)
+    {
+      tree func_params, call_exp;
+      dst_block_component = build_fold_addr_expr (dst_block_component);
+      func_params = tree_cons (NULL_TREE, dst_block_component,
+                               tree_cons (NULL_TREE, src_block_component,
+                                          tree_cons (NULL_TREE,
+                                                     build_int_cst (integer_type_node, 0),
+                                                     NULL_TREE)));
+      call_exp = build_function_call (which_function_decl, func_params);
+      add_stmt (call_exp);
     }
+    /* APPLE LOCAL end radar 6175959 */
+  }
 
   /* For each __block declared variable used in |...| Must generate call to:
      _Block_byref_assign_copy(&_dest->myImportedBlock, _src->myImportedBlock)
@@ -20964,6 +21201,30 @@
   /* free (arg_info); */
 }
 
+/* APPLE LOCAL begin radar 6175959 */
+static tree
+block_object_dispose (tree src_block_component)
+{
+  tree func_params;
+  if (!block_object_dispose_func_decl &&
+      !(block_object_dispose_func_decl = lookup_name (get_identifier ("_Block_object_dispose"))))
+    {
+      tree func_type =
+      build_function_type (void_type_node,
+                           tree_cons (NULL_TREE, ptr_type_node,
+                                      tree_cons (NULL_TREE, integer_type_node, void_list_node)));
+
+      block_object_dispose_func_decl = builtin_function ("_Block_object_dispose", func_type,
+                                       0, NOT_BUILT_IN, 0, NULL_TREE);
+     TREE_NOTHROW (block_object_dispose_func_decl) = 0;
+    }
+    func_params = tree_cons (NULL_TREE, src_block_component,
+                             tree_cons (NULL_TREE,
+                                        build_int_cst (integer_type_node, 0), NULL_TREE));
+    return build_function_call (block_object_dispose_func_decl, func_params);
+}
+/* APPLE LOCAL end radar 6175959 */
+
 static void
 synth_destroy_helper_block_func (struct block_sema_info * block_impl)
 {
@@ -21010,22 +21271,27 @@
       if (TREE_CODE (TREE_TYPE (p)) == BLOCK_POINTER_TYPE)
       {
         tree func_params, call_exp;
+	/* APPLE LOCAL begin radar 6175959 */
         /* _Block_destroy(_src->myImportedClosure); */
         /* _Block_destroy (void *); */
         /* Build a: void _Block_destroy (void *) if not done already. */
         if (!block_destroy_decl &&
-	    !(block_destroy_decl = lookup_name (get_identifier ("_Block_destroy"))))
+            !(block_destroy_decl = lookup_name (get_identifier ("_Block_destroy"))))
         {
           tree func_type =
           build_function_type (void_type_node,
-                               tree_cons (NULL_TREE, ptr_type_node, void_list_node));
+                               tree_cons (NULL_TREE, ptr_type_node,
+                                          tree_cons (NULL_TREE, integer_type_node, void_list_node)));
 
           block_destroy_decl = builtin_function ("_Block_destroy", func_type,
-                                                     0, NOT_BUILT_IN, 0, NULL_TREE);
+                                                 0, NOT_BUILT_IN, 0, NULL_TREE);
           TREE_NOTHROW (block_destroy_decl) = 0;
         }
-        func_params = tree_cons (NULL_TREE, src_block_component, NULL_TREE);
+        func_params = tree_cons (NULL_TREE, src_block_component,
+                                 tree_cons (NULL_TREE,
+                                            build_int_cst (integer_type_node, 0), NULL_TREE));
         call_exp = build_function_call (block_destroy_decl, func_params);
+        /* APPLE LOCAL end radar 6175959 */
         add_stmt (call_exp);
       }
       /* APPLE LOCAL begin radar 6214617 */
@@ -21040,13 +21306,15 @@
       else
       {
         tree rel_exp;
-        /* [_src->imported_object_0 release]; */
-        rel_exp = release_block_component (src_block_component);
+        /* APPLE LOCAL begin radar 6175959 */
+        /* _Block_object_dispose(_src->imported_object_0, 0); */
+        rel_exp = block_object_dispose (src_block_component);
+        /* APPLE LOCAL end radar 6175959 */
         add_stmt (rel_exp);
       }
     }
 
-  /* For each __byref declared variable used in |...| Must generate call to:
+  /* For each __block declared variable used in |...| Must generate call to:
    _Block_byref_release(_src->myImportedClosure)
    */
   for (chain = block_impl->block_byref_decl_list; chain;
@@ -21239,6 +21507,8 @@
   /* APPLE LOCAL begin radar 6237713 */
   if (cp_lexer_peek_token (parser->lexer)->keyword == RID_ATTRIBUTE)
     attributes = cp_parser_attributes_opt (parser);
+  /* APPLE LOCAL radar 6246527 */
+  any_recognized_block_attribute (attributes);
   decl_attributes (&cur_block->helper_func_decl, attributes, 0);
   /* APPLE LOCAL end radar 6237713 */  
 
@@ -21355,17 +21625,19 @@
 
 /* APPLE LOCAL begin blocks 6040305 (ch) */
 /* build_byref_local_var_access - converts EXPR to:
-   EXPR.forwarding-><decl-name>.
+   EXPR.__forwarding-><decl-name>.
 */
 tree
 build_byref_local_var_access (tree expr, tree decl_name)
 {
-  tree exp = build_component_ref (expr, get_identifier ("forwarding"));
+  tree exp = build_component_ref (expr, get_identifier ("__forwarding"));
   exp = build_indirect_ref (exp, "unary *");
   exp = build_component_ref (exp, decl_name);
   return exp;
 }
 
+#define BINDING_VALUE(b) ((b)->value)
+
 /**
   build_block_byref_decl - This routine inserts a variable declared as a
   'byref' variable using the |...| syntax in helper function's outer-most scope.
@@ -21373,13 +21645,67 @@
 tree
 build_block_byref_decl (tree name, tree decl, tree exp)
 {
+  tree ptr_type, byref_decl;
+  /* APPLE LOCAL begin radar 6225809 */
+  if (cur_block->prev_block_info) {
+    /* Traverse enclosing blocks. Insert a __block variable in
+     each enclosing block which has no declaration of this
+     variable. This is to ensure that the current (inner) block
+     gets the __block version of the variable; */
+    struct block_sema_info *cb = cur_block->prev_block_info;
+    while (cb) {
+      struct cxx_binding *b = I_SYMBOL_BINDING (name);
+      gcc_assert (b);
+      gcc_assert (BINDING_VALUE (b));
+      gcc_assert (TREE_CODE (BINDING_VALUE (b)) == VAR_DECL
+                  || TREE_CODE (BINDING_VALUE (b)) == PARM_DECL);
+      /* Find the first declaration not in current block. */
+      while (b && BINDING_VALUE (b)
+             && (TREE_CODE (BINDING_VALUE (b)) == VAR_DECL 
+                 || TREE_CODE (BINDING_VALUE (b)) == PARM_DECL)
+             && DECL_CONTEXT (BINDING_VALUE (b)) == cur_block->helper_func_decl)
+      {
+        /* FIXME: This can't happen?!  */
+        abort ();
+        /* b = b->previous; */
+      }
+      
+      gcc_assert (b);
+      gcc_assert (BINDING_VALUE (b));
+      gcc_assert (TREE_CODE (BINDING_VALUE (b)) == VAR_DECL 
+                  || TREE_CODE (BINDING_VALUE (b)) == PARM_DECL);
+      
+      /* Is the next declaration not in the enclosing block? */
+      if (b && BINDING_VALUE (b)
+          && (TREE_CODE (BINDING_VALUE (b)) == VAR_DECL 
+              || TREE_CODE (BINDING_VALUE (b)) == PARM_DECL)
+          && DECL_CONTEXT (BINDING_VALUE (b)) != cb->helper_func_decl)
+      {
+        /* No declaration of variable seen in the block. Must insert one. */
+        /* FIXME: does this push enough?  scope?  */
+        struct cp_binding_level *save_scope = current_binding_level;
+        struct block_sema_info *save_current_block = cur_block;
+        tree save_current_function_decl = current_function_decl;
+        current_binding_level = cb->cp_the_scope;
+        cur_block = cb;
+        current_function_decl = cb->helper_func_decl;
+        decl = build_block_byref_decl (name, decl, exp);
+        cur_block = save_current_block;
+        current_binding_level = save_scope;
+        current_function_decl = save_current_function_decl;
+      }
+      cb = cb->prev_block_info; 
+    }
+  }
+  /* APPLE LOCAL end radar 6225809 */
+  
   /* If it is already a byref declaration, do not add the pointer type
      because such declarations already have the pointer type
      added. This happens when we have two nested byref declarations in
      nested blocks. */
-  tree ptr_type = (TREE_CODE (decl) == VAR_DECL && BLOCK_DECL_BYREF (decl))
-                   ? TREE_TYPE (decl) : build_pointer_type (TREE_TYPE (decl));
-  tree byref_decl = build_decl (VAR_DECL, name, ptr_type);
+  ptr_type = (TREE_CODE (decl) == VAR_DECL && BLOCK_DECL_BYREF (decl))
+              ? TREE_TYPE (decl) : build_pointer_type (TREE_TYPE (decl));
+  byref_decl = build_decl (VAR_DECL, name, ptr_type);
   DECL_CONTEXT (byref_decl) = current_function_decl;
   BLOCK_DECL_BYREF (byref_decl) = 1;
 
@@ -21401,8 +21727,8 @@
   /* APPLE LOCAL end radar 6083129 -  byref escapes (cp) */
   cur_block->block_byref_decl_list =
     tree_cons (NULL_TREE, byref_decl, cur_block->block_byref_decl_list);
-  cur_block->block_original_byref_decl_list =
-    tree_cons (NULL_TREE, exp, cur_block->block_original_byref_decl_list);
+  /* APPLE LOCAL radar 5847213 */
+  /* build of block_original_byref_decl_list us removed. */
   /* APPLE LOCAL begin radar 6144664  */
   DECL_SOURCE_LOCATION (byref_decl)
     = DECL_SOURCE_LOCATION (cur_block->helper_func_decl);
@@ -21410,8 +21736,6 @@
   return byref_decl;
 }
 
-#define BINDING_VALUE(b) ((b)->value)
-
 /**
   build_block_ref_decl - This routine inserts a copied-in variable (a variable
   referenced in the block but whose scope is outside the block) in helper
@@ -21525,64 +21849,74 @@
   return ref_decl;
 }
 
-/** build_block_internal_types - This routine builds the block type:
- struct __invoke_impl {
- void   *isa;
- int32_t Flags;
- int32_t Size;
- void *FuncPtr;
- } *invoke_impl_ptr_type;
- */
-void
-build_block_internal_types (void)
+/* APPLE LOCAL begin radar 5847213 - radar 6329245 */
+static GTY (())  tree descriptor_ptr_type;
+static GTY (())  tree descriptor_ptr_type_with_copydispose;
+/** build_block_descriptor_type - This routine builds following internal type:
+ struct __block_descriptor {
+ unsigned long int reserved;     // NULL
+ unsigned long int Size;  // sizeof(struct Block_literal_1)
+
+ // optional helper functions
+ void *CopyFuncPtr; // When BLOCK_HAS_COPY_DISPOSE is set (withCopyDispose true)
+ void *DestroyFuncPtr; // When BLOCK_HAS_COPY_DISPOSE is set (withCopyDispose true)
+} *descriptor_ptr_type;
+
+Objects of this type will always be static. This is one main component of abi change.
+*/
+tree
+build_block_descriptor_type (bool withCopyDispose)
 {
-  tree fields = NULL_TREE, field_decl;
-  tree invoke_impl_type;
+  tree field_decl_chain = NULL_TREE, field_decl;
+  tree main_type;
+
+  if (withCopyDispose && descriptor_ptr_type_with_copydispose)
+    return descriptor_ptr_type_with_copydispose;
+  if (!withCopyDispose && descriptor_ptr_type)
+    return descriptor_ptr_type;
+
+  main_type = make_aggr_type (RECORD_TYPE);
+  xref_basetypes (main_type, NULL_TREE);
+
+  /* unsigned long int reserved; */
+  field_decl = build_decl (FIELD_DECL, get_identifier ("reserved"), long_unsigned_type_node);
+  TREE_CHAIN (field_decl) = field_decl_chain;
+  field_decl_chain = field_decl;
+
+  /* unsigned long int Size; */
+  field_decl = build_decl (FIELD_DECL, get_identifier ("Size"), long_unsigned_type_node);
+  TREE_CHAIN (field_decl) = field_decl_chain;
+  field_decl_chain = field_decl;
 
-  /* If a user-declaration of "struct __invoke_impl" is seen, use it. */
-  invoke_impl_type = lookup_name_prefer_type (get_identifier ("__invoke_impl"), 2);
-  if (invoke_impl_type)
+  if (withCopyDispose)
   {
-    invoke_impl_ptr_type = build_pointer_type (invoke_impl_type);
-    return;
+    /* void *CopyFuncPtr; */
+    field_decl = build_decl (FIELD_DECL, get_identifier ("CopyFuncPtr"), ptr_type_node);
+    TREE_CHAIN (field_decl) = field_decl_chain;
+    field_decl_chain = field_decl;
+    /* void *DestroyFuncPtr; */
+    field_decl = build_decl (FIELD_DECL, get_identifier ("DestroyFuncPtr"), ptr_type_node);
+    TREE_CHAIN (field_decl) = field_decl_chain;
+    field_decl_chain = field_decl;
   }
 
-  push_to_top_level ();
-
-  /* invoke_impl_type = start_struct (RECORD_TYPE, get_identifier ("__invoke_impl")); */
-  invoke_impl_type = make_aggr_type (RECORD_TYPE);
-  xref_basetypes (invoke_impl_type, NULL_TREE);
-
-  /* void *isa; */
-  field_decl = build_decl (FIELD_DECL, get_identifier ("isa"), ptr_type_node);
-  TREE_CHAIN (field_decl) = fields;
-  fields = field_decl;
-
-  /* int32_t Flags; */
-  field_decl = build_decl (FIELD_DECL, get_identifier ("Flags"), unsigned_type_node);
-  TREE_CHAIN (field_decl) = fields;
-  fields = field_decl;
-
-  /* int32_t Size */
-  field_decl = build_decl (FIELD_DECL, get_identifier ("Size"), unsigned_type_node);
-  TREE_CHAIN (field_decl) = fields;
-  fields = field_decl;
-
-  /* void *FuncPtr; */
-  field_decl = build_decl (FIELD_DECL, get_identifier ("FuncPtr"), ptr_type_node);
-  TREE_CHAIN (field_decl) = fields;
-  fields = field_decl;
-
-  /* Mark this struct as being a block struct rather than a 'normal'
-   struct.  */
-  TYPE_BLOCK_IMPL_STRUCT (invoke_impl_type) = 1;
-  /* finish_struct (invoke_impl_type, field_decl_chain, NULL_TREE); */
-  finish_builtin_struct (invoke_impl_type, "__invoke_impl", fields, NULL_TREE);
-  /* APPLE LOCAL radar 6169527 */
-  CLASSTYPE_AS_BASE (invoke_impl_type) = invoke_impl_type;
-  pop_from_top_level ();
-  invoke_impl_ptr_type = build_pointer_type (invoke_impl_type);
+   /* Mark this struct as being a block struct rather than a 'normal'
+      struct.  */
+  TYPE_BLOCK_IMPL_STRUCT (main_type) = 1;
+  if (withCopyDispose)
+    finish_builtin_struct (main_type, "__block_descriptor_withcopydispose", field_decl_chain, NULL_TREE);
+  else
+    finish_builtin_struct (main_type, "__block_descriptor", field_decl_chain, NULL_TREE);
+  CLASSTYPE_AS_BASE (main_type) = main_type;
+
+  main_type = build_pointer_type (main_type);
+  if (withCopyDispose)
+    descriptor_ptr_type_with_copydispose = main_type;
+  else
+    descriptor_ptr_type = main_type;
+  return main_type;
 }
+/* APPLE LOCAL end radar 5847213 - radar 6329245 */
 
 cp_declarator *
 make_block_pointer_declarator (tree attributes,
@@ -21592,9 +21926,9 @@
   struct cp_declarator *itarget = target;
   struct cp_declarator *ret = make_declarator (cdk_block_pointer);
 
-  /* Closure contructs seen -- generate supporting types.  */
-  if (!invoke_impl_ptr_type)
-    build_block_internal_types ();
+  /* APPLE LOCAL radar 5847213 */
+  /* code removed */
+
 
   ret->attributes = attributes;
   ret->declarator = itarget;
@@ -21666,11 +22000,15 @@
   tree decl, block_component;
   tree_stmt_iterator i;
   tree initialization_stmt;
+  /* APPLE LOCAL radar 6163705  */
+  int save_line = LOCATION_LINE (input_location);
 
   decl = component;
   block_component = build_component_ref (build_indirect_ref (self_parm, "->"),
 					 DECL_NAME (component));
   gcc_assert (block_component);
+  /* APPLE LOCAL radar 6163705  */
+  LOCATION_LINE (input_location) = DECL_SOURCE_LINE (decl) - 1;
   DECL_EXTERNAL (decl) = 0;
   TREE_STATIC (decl) = 0;
   TREE_USED (decl) = 1;
@@ -21679,7 +22017,9 @@
   initialization_stmt = push_stmt_list();
   cp_finish_decl (decl, block_component, 0, 0, LOOKUP_ONLYCONVERTING);
   initialization_stmt = pop_stmt_list (initialization_stmt);
-  /* Prepend a initialization_stmt statement to the statement list. */
+  /* APPLE LOCAL radar 6163705  */
+  LOCATION_LINE (input_location) = save_line;
+ /* Prepend a initialization_stmt statement to the statement list. */
   i = tsi_start (stmt);
   tsi_link_before (&i, initialization_stmt, TSI_SAME_STMT);
 }
@@ -21710,6 +22050,11 @@
   i = tsi_start (stmt);
   decl_stmt = build_stmt (DECL_EXPR, decl);
   SET_EXPR_LOCATION (decl_stmt, DECL_SOURCE_LOCATION (decl));
+  /* APPLE LOCAL begin radar 6163705, Blocks prologues  */
+  /* Give the prologue statements a line number of one before the beginning of
+     the function, to make them easily identifiable later.  */
+  EXPR_LINENO (decl_stmt) =  DECL_SOURCE_LINE (decl) - 1;
+  /* APPLE LOCAL end radar 6163705, Blocks prologues  */
   decl_stmt = build3 (BIND_EXPR, void_type_node, decl, decl_stmt, NULL);
   TREE_SIDE_EFFECTS (decl_stmt) = 1;
   

Modified: llvm-gcc-4.2/trunk/gcc/cp/tree.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/cp/tree.c?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/cp/tree.c (original)
+++ llvm-gcc-4.2/trunk/gcc/cp/tree.c Mon Nov  3 01:33:15 2008
@@ -1717,6 +1717,15 @@
       && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (current_class_ref)),
 		      current_class_type))
     decl = current_class_ref;
+  /* APPLE LOCAL begin radar 6154598 */
+    else if (cur_block)
+    {
+      tree this_copiedin_var = lookup_name (this_identifier);
+      gcc_assert (!current_class_ref);
+      gcc_assert (this_copiedin_var);
+      decl = build_x_arrow (this_copiedin_var);
+    }  
+  /* APPLE LOCAL end radar 6154598 */
   else
     decl = build_dummy_object (context);
 

Modified: llvm-gcc-4.2/trunk/gcc/cp/typeck.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/cp/typeck.c?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/cp/typeck.c (original)
+++ llvm-gcc-4.2/trunk/gcc/cp/typeck.c Mon Nov  3 01:33:15 2008
@@ -531,8 +531,8 @@
   if (c_dialect_objc () && TREE_CODE (t1) == POINTER_TYPE
       && TREE_CODE (t2) == POINTER_TYPE)
     {
-      /* APPLE LOCAL radar 4229905 */
-      if (objc_have_common_type (t1, t2, -3, NULL_TREE))
+      /* APPLE LOCAL radar 4229905 - radar 6231433 */
+      if (objc_have_common_type (t1, t2, -3, NULL_TREE, location))
         /* APPLE LOCAL 4154928 */
         return objc_common_type (t1, t2);
     }
@@ -2762,43 +2762,46 @@
 }
 
 /* APPLE LOCAL begin blocks 6040305 (cm) */
+/* APPLE LOCAL begin radar 5847213 - radar 6329245 */
 /**
  build_block_call - Routine to build a block call; as in:
- ((double(*)(struct invok_impl *, int))(BLOCK_PTR_VAR->FuncPtr))(I, 42);
+  ((double(*)(void *, int))(BLOCK_PTR_EXP->__FuncPtr))(I, 42);
  FNTYPE is the original function type derived from the syntax.
- FUNCTION is the4 block pointer variable.
+ BLOCK_PTR_EXP is the block pointer variable.
  PARAMS is the parameter list.
- */
+*/
 static tree
-build_block_call (tree fntype, tree function, tree params)
+build_block_call (tree fntype, tree block_ptr_exp, tree params)
 {
-  tree block_ptr_exp;
   tree function_ptr_exp;
   tree typelist;
   tree result;
   
-  /* (struct invok_impl *)BLOCK_PTR_VAR */
   /* First convert it to 'void *'. */
-  block_ptr_exp = convert (ptr_type_node, function);
-  gcc_assert (invoke_impl_ptr_type);
-  block_ptr_exp = convert (invoke_impl_ptr_type, block_ptr_exp);
-  params = tree_cons (NULL_TREE, block_ptr_exp, params);
-  /* BLOCK_PTR_VAR->FuncPtr */
+  block_ptr_exp = convert (ptr_type_node, block_ptr_exp);
+  gcc_assert (generic_block_literal_struct_type);
+  block_ptr_exp = convert (build_pointer_type (generic_block_literal_struct_type),
+                           block_ptr_exp);
+
+  /* BLOCK_PTR_VAR->__FuncPtr */
   function_ptr_exp =
-  finish_class_member_access_expr (build_indirect_ref (block_ptr_exp, "->"),
-                       get_identifier ("FuncPtr"), false);
+    finish_class_member_access_expr (build_indirect_ref (block_ptr_exp, "->"),
+                       		     get_identifier ("__FuncPtr"), false);
+  gcc_assert (function_ptr_exp);
   
-  /* Build: result_type(*)(struct invok_impl *, function-arg-type-list) */
+  /* Build: result_type(*)(void *, function-arg-type-list) */
   typelist = TYPE_ARG_TYPES (fntype);
-  typelist = tree_cons (NULL_TREE, invoke_impl_ptr_type, typelist);
+  typelist = tree_cons (NULL_TREE, ptr_type_node, typelist);
   fntype = build_function_type (TREE_TYPE (fntype), typelist);
   function_ptr_exp = convert (build_pointer_type (fntype), function_ptr_exp);
+  params = tree_cons (NULL_TREE, block_ptr_exp, params);
   result = build3 (CALL_EXPR, TREE_TYPE (fntype),
 		   function_ptr_exp, params, NULL_TREE);
   /* FIXME: should do more from build_cxx_call */
   result = convert_from_reference (result);
   return result;
 }
+/* APPLE LOCAL end radar 5847213 - radar 6329245 */
 /* APPLE LOCAL end blocks 6040305 (cm) */
 
 tree
@@ -6717,7 +6720,8 @@
 	    }
 	}
 
-      if (objc_compare_types (type, rhstype, parmno, rname))
+      /* APPLE LOCAL file radar 6231433 */
+      if (objc_compare_types (type, rhstype, parmno, rname, "comparison"))
 	/* APPLE LOCAL radar 4874632 */
 	new_rhs = convert (type, rhs);
     }

Modified: llvm-gcc-4.2/trunk/gcc/dwarf2out.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/dwarf2out.c?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/dwarf2out.c (original)
+++ llvm-gcc-4.2/trunk/gcc/dwarf2out.c Mon Nov  3 01:33:15 2008
@@ -163,6 +163,8 @@
 static GTY(()) section *debug_str_section;
 static GTY(()) section *debug_ranges_section;
 static GTY(()) section *debug_frame_section;
+/* APPLE LOCAL radar 6275985 debug inlined section  */
+static GTY(()) section *debug_inlined_section;
 
 /* How to start an assembler comment.  */
 #ifndef ASM_COMMENT_START
@@ -330,6 +332,8 @@
   const char *str;
   unsigned int refcount;
   unsigned int form;
+  /* APPLE LOCAL radar 6275985 debug inlined section  */
+  bool  is_fn_name;
   char *label;
 };
 
@@ -3706,6 +3710,8 @@
 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
 typedef struct pubname_struct *pubname_ref;
 typedef struct dw_ranges_struct *dw_ranges_ref;
+/* APPLE LOCAL radar 6275985 debug inlined section  */
+typedef struct inlined_entry_struct *inlined_ref;
 
 /* Each entry in the line_info_table maintains the file and
    line number associated with the label generated for that
@@ -3787,6 +3793,20 @@
 DEF_VEC_O(pubname_entry);
 DEF_VEC_ALLOC_O(pubname_entry, gc);
 /* APPLE LOCAL end pubtypes, approved for 4.3 4535968  */
+/* APPLE LOCAL begin radar 6275985 debug inlined section  */
+DEF_VEC_O(dw_die_ref);
+DEF_VEC_ALLOC_O(dw_die_ref, gc);
+
+typedef struct inlined_entry_struct GTY (())
+{
+  dw_die_ref origin_die;
+  VEC(dw_die_ref,gc) *inlined_instances;
+}
+inlined_entry;
+
+DEF_VEC_O(inlined_entry);
+DEF_VEC_ALLOC_O(inlined_entry, gc);
+/* APPLE LOCAL end radar 6275985 debug inlined section  */
 
 struct dw_ranges_struct GTY(())
 {
@@ -3838,6 +3858,11 @@
 /* Fixed size portion of public names info.  */
 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
 
+/* APPLE LOCAL begin radar 6275985 debug inlined section  */
+/* Fixed size portion of inlined section info.  */
+#define DWARF_INLINED_HEADER_SIZE  (3)
+/* APPLE LOCAL end radar 6275985 debug inlined section  */
+
 /* Fixed size portion of the address range info.  */
 #define DWARF_ARANGES_HEADER_SIZE					\
   (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4,	\
@@ -3978,6 +4003,9 @@
 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
 /* APPLE LOCAL end pubtypes, approved for 4.3 4535968  */
 
+/* APPLE LOCAL radar 6275985 debug inlined section  */
+static GTY (()) VEC (inlined_entry, gc) * debug_inlined_table;
+
 /* Array of dies for which we should generate .debug_arange info.  */
 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
 
@@ -4152,6 +4180,8 @@
 static void unmark_all_dies (dw_die_ref);
 /* APPLE LOCAL pubtypes, approved for 4.3 4535968  */
 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
+/* APPLE LOCAL radar 6275985 debug inlined section  */
+static unsigned long size_of_inlined (VEC (inlined_entry,gc) *);
 static unsigned long size_of_aranges (void);
 static enum dwarf_form value_format (dw_attr_ref);
 static void output_value_format (dw_attr_ref);
@@ -4166,6 +4196,10 @@
 static void add_pubtype (tree, dw_die_ref);
 static void output_pubnames (VEC (pubname_entry,gc) *);
 /* APPLE LOCAL end pubtypes, approved for 4.3 4535968  */
+/* APPLE LOCAL begin radar 6275985 debug inlined section  */
+static void add_inlined_section_entry (dw_die_ref);
+static void output_debug_inlined_section (VEC (inlined_entry,gc) *);
+/* APPLE LOCAL end radar 6275985 debug inlined section  */
 static void add_arange (tree, dw_die_ref);
 static void output_aranges (void);
 static unsigned int add_ranges (tree);
@@ -5099,6 +5133,18 @@
   node->str = ggc_strdup (str);
   node->refcount++;
 
+  /* APPLE LOCAL begin radar 6275985 debug inlined section  */
+#ifdef DEBUG_INLINED_SECTION
+  /* Force the names of functions (which may be inlined) to be in the
+     debug string section (i.e. string pointers).  */
+  if (die
+      && die->die_tag == DW_TAG_subprogram
+      && ((attr_kind == DW_AT_name)
+	  || (attr_kind == DW_AT_MIPS_linkage_name)))
+    node->is_fn_name = true;
+#endif
+  /* APPLE LOCAL end radar 6275985 debug inlined section  */
+
   attr.dw_attr = attr_kind;
   attr.dw_attr_val.val_class = dw_val_class_str;
   attr.dw_attr_val.v.val_str = node;
@@ -5130,17 +5176,23 @@
 
   len = strlen (node->str) + 1;
 
+  /* APPLE LOCAL begin radar 6275985 debug inlined section  */
+  /* Ths sentence below is false.  If the string is a function name we
+     always want it to go into the debug_str section.  */
   /* If the string is shorter or equal to the size of the reference, it is
      always better to put it inline.  */
-  if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
+  if ((len <= DWARF_OFFSET_SIZE || node->refcount == 0)
+      && !node->is_fn_name)
     return node->form = DW_FORM_string;
 
   /* If we cannot expect the linker to merge strings in .debug_str
      section, only put it into .debug_str if it is worth even in this
      single module.  */
   if ((debug_str_section->common.flags & SECTION_MERGE) == 0
-      && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
+      && (len - DWARF_OFFSET_SIZE) * node->refcount <= len
+      && !node->is_fn_name)
     return node->form = DW_FORM_string;
+  /* APPLE LOCAL end radar 6275985 debug inlined section  */
 
   ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
   ++dw2_string_counter;
@@ -5374,6 +5426,29 @@
   return a->dw_attr_val.v.val_lbl_id;
 }
 
+/* APPLE LOCAL begin radar 6275985 debug inlined section  */
+
+/* Get the attribute of type attr_kind, if the die has it.
+   This differs from get_AT in that it does NOT search any
+   abstract origin or specification dies; it ONLY looks directly
+   at the die that was passed in.  */
+
+static dw_attr_ref
+has_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
+{
+  dw_attr_ref a;
+  unsigned ix;
+
+  if (! die)
+    return NULL;
+
+  for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
+    if (a->dw_attr == attr_kind)
+      return a;
+
+  return NULL;
+}
+/* APPLE LOCAL end radar 6275985 debug inlined section  */
 /* Get the attribute of type attr_kind.  */
 
 static dw_attr_ref
@@ -6636,7 +6711,7 @@
      if appropriate.  */
   if (! die->die_child)
     return;
-  /* APPLE LOCAL end radar 6066486  */
+  /* APPLE LOCAL end radar 6066486 - Code moved from above.  */
 
   if (die->die_parent && die != die->die_parent->die_child)
     add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
@@ -6908,6 +6983,27 @@
       unmark_all_dies (AT_ref (a));
 }
 
+/* APPLE LOCAL begin radar 6275985 debug inlined section  */
+static unsigned long
+size_of_inlined (VEC (inlined_entry, gc) * inlined_dies)
+{
+  unsigned long size;
+  unsigned i;
+  unsigned num_entries;
+  inlined_ref iptr;
+
+  size = DWARF_INLINED_HEADER_SIZE;
+  
+  for (i = 0; VEC_iterate (inlined_entry, inlined_dies, i, iptr); i++)
+    {
+      num_entries = VEC_length (dw_die_ref, iptr->inlined_instances);
+      size += (2 * DWARF_OFFSET_SIZE) + (num_entries * DWARF2_ADDR_SIZE)
+	+ (num_entries * DWARF_OFFSET_SIZE) + size_of_uleb128 (num_entries);
+    }
+
+  return size;
+}
+/* APPLE LOCAL end radar 6275985 debug inlined section  */
 /* APPLE LOCAL begin pubtypes, approved for 4.3 4535968  */
 /* Return the size of the .debug_pubnames or .debug_pubtypes table
    generated for the compilation unit.  */
@@ -7547,6 +7643,121 @@
     }
 }
 
+/* APPLE LOCAL begin radar 6275985 debug inlined section  */
+static void 
+add_inlined_section_entry (dw_die_ref die)
+{
+  unsigned i;
+  bool found = false;
+  inlined_ref iptr;
+  dw_die_ref current_origin_die = get_AT_ref (die, DW_AT_abstract_origin);
+
+  /* APPLE LOCAL begin radar 6292557  */
+  if (!current_origin_die)
+    return;
+  /* APPLE LOCAL end radar 6292557  */
+
+  if (!has_AT (die, DW_AT_low_pc))
+    return;
+
+  for (i = 0; VEC_iterate (inlined_entry, debug_inlined_table, i, iptr); i++)
+    {
+      if (iptr->origin_die == current_origin_die)
+	{
+	  VEC_safe_push (dw_die_ref, gc, iptr->inlined_instances, &die);
+	  found = true;
+	}
+    }
+
+  if (!found)
+    {
+      inlined_entry *new_entry = (inlined_entry *) xmalloc (sizeof (inlined_entry));
+      new_entry->origin_die = current_origin_die;
+      new_entry->inlined_instances = VEC_alloc (dw_die_ref, gc, 32);
+      VEC_safe_push (dw_die_ref, gc, new_entry->inlined_instances, &die);
+      VEC_safe_push (inlined_entry, gc, debug_inlined_table, new_entry);
+    }
+}
+
+static void
+output_debug_inlined_section (VEC (inlined_entry, gc) * inlined_dies)
+{
+  unsigned i;
+  unsigned long inlined_length = size_of_inlined (inlined_dies);
+  inlined_entry *iptr;
+
+  if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
+    dw2_asm_output_data (4, 0xffffffff,
+      "Initial length escape value indicating 64-bit DWARF extension");
+  dw2_asm_output_data (DWARF_OFFSET_SIZE, inlined_length,
+		       "Length of Inlined Subroutines Info");
+  dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
+  /*
+    dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
+			 debug_info_section,
+			 "Offset of Compilation Unit Info");
+    dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
+		       "Compilation Unit Length");
+  */
+  dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
+
+  for (i = 0; VEC_iterate (inlined_entry, inlined_dies, i, iptr); i++)
+    {
+      dw_attr_ref name_attr;
+      dw_attr_ref mips_name_attr;
+      dw_die_ref *diep;
+      unsigned j;
+      unsigned num_entries = VEC_length (dw_die_ref, iptr->inlined_instances);
+      dw_die_ref origin_die = iptr->origin_die;
+
+      mips_name_attr = get_AT (origin_die, DW_AT_MIPS_linkage_name);
+      name_attr = get_AT (origin_die, DW_AT_name);
+
+      if (!mips_name_attr)
+	mips_name_attr = name_attr;
+
+      gcc_assert (origin_die != NULL);
+      gcc_assert (name_attr != NULL);
+      gcc_assert (mips_name_attr != NULL);
+      gcc_assert (num_entries > 0);
+      gcc_assert (AT_string_form (name_attr) == DW_FORM_strp);
+      gcc_assert (AT_string_form (mips_name_attr) == DW_FORM_strp);
+
+      /*
+	dw2_asm_output_data (DWARF_OFFSET_SIZE, origin_die->die_offset,
+			     "Origin die offset");
+      */
+
+      dw2_asm_output_offset (DWARF_OFFSET_SIZE,
+			     mips_name_attr->dw_attr_val.v.val_str->label,
+			     debug_str_section,
+			     "MIPS linkage name: \"%s\"", 
+			     AT_string (mips_name_attr));
+
+      dw2_asm_output_offset (DWARF_OFFSET_SIZE,
+			     name_attr->dw_attr_val.v.val_str->label,
+			     debug_str_section,
+			     "Function name: \"%s\"", AT_string (name_attr));
+
+      dw2_asm_output_data_uleb128 (num_entries, NULL);
+
+      for (j = 0; VEC_iterate (dw_die_ref, iptr->inlined_instances, j, diep);
+	   j++)
+	{
+	  const char *low_pc = get_AT_low_pc (*diep);
+
+	  gcc_assert (low_pc != NULL);
+
+	  dw2_asm_output_data (DWARF_OFFSET_SIZE, (*diep)->die_offset,
+			       "inlined subroutine die offset");
+	  dw2_asm_output_addr (DWARF2_ADDR_SIZE, low_pc, "%s", 
+			       "Low PC address");
+
+	}
+    }
+}
+/* APPLE LOCAL end radar 6275985 debug inlined section  */
+
 /* Output the public names table used to speed up access to externally
    visible names; or the public types table used to find type
    definitions.  For now, only generate entries for externally
@@ -8774,8 +8985,7 @@
   if (sub_die != NULL)
     add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
 
-  /* APPLE LOCAL begin radar 5359827 add named pointer types to
-     pubtype table  */
+  /* APPLE LOCAL begin radar 5359827 add named pointer types to pubtype table  */
   if (mod_type_die
       && mod_type_die->die_tag  == DW_TAG_pointer_type 
       && get_AT (mod_type_die, DW_AT_name))
@@ -11262,7 +11472,22 @@
      here.  */
 
   if (origin_die)
+    /* APPLE LOCAL begin radar 6275985 debug inlined section  */
+     {
       add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
+      if (die->die_tag == DW_TAG_inlined_subroutine)
+	{
+	  dw_attr_ref inline_attr = get_AT (origin_die, DW_AT_inline);
+	  if (!inline_attr)
+	    {
+	      if (DECL_P (origin) && DECL_DECLARED_INLINE_P (origin))
+		add_AT_unsigned  (origin_die, DW_AT_inline, DW_INL_declared_inlined);
+	      else
+		add_AT_unsigned (origin_die, DW_AT_inline, DW_INL_inlined);
+	    }
+	}
+     }
+    /* APPLE LOCAL end radar 6275985 debug inlined section  */
 }
 
 /* We do not currently support the pure_virtual attribute.  */
@@ -11500,15 +11725,18 @@
   enum tree_code code  = TREE_CODE (type);
   dw_die_ref type_die  = NULL;
 
+/* APPLE LOCAL begin radar 5847213 */
   /* APPLE LOCAL begin radar 5811943 - Fix type of pointers to blocks  */
   /* APPLE LOCAL - radar 6113240 */
-  if (code == BLOCK_POINTER_TYPE && invoke_impl_ptr_type)
+  /* APPLE LOCAL begin radar 6300081  */
+  if (code == BLOCK_POINTER_TYPE && generic_block_literal_struct_type)
     {
-      /* APPLE LOCAL - radar 6113240 Removed gcc_assert */
-      type = invoke_impl_ptr_type;
+      type = build_pointer_type (generic_block_literal_struct_type);
       code = TREE_CODE (type);
     }
+  /* APPLE LOCAL end radar 6300081  */
   /* APPLE LOCAL end radar 5811943 - Fix type of pointers to Blocks  */
+/* APPLE LOCAL end radar 5847213 */
 
   /* ??? If this type is an unnamed subrange type of an integral or
      floating-point type, use the inner type.  This is because we have no
@@ -12474,11 +12702,28 @@
   if (TREE_CODE (block_struct) != RECORD_TYPE)
     return ret_type;
 
-  if ((! TYPE_NAME (block_struct))
-      || (! IDENTIFIER_POINTER (TYPE_NAME (block_struct)))
-      || (strncmp (IDENTIFIER_POINTER (TYPE_NAME (block_struct)),
+  /* APPLE LOCAL begin radar 6237086  */
+  /* Look for a type name, and make sure it contains the __Block_byref_
+     substring.  */
+
+  if (! TYPE_NAME (block_struct))
+    return ret_type;
+
+  if (TREE_CODE (TYPE_NAME (block_struct)) != IDENTIFIER_NODE
+      && TREE_CODE (TYPE_NAME (block_struct)) != TYPE_DECL)
+    return ret_type;
+
+  if (TREE_CODE (TYPE_NAME (block_struct)) == IDENTIFIER_NODE
+      && (strncmp (IDENTIFIER_POINTER (TYPE_NAME (block_struct)),
 		   "__Block_byref_", 14) != 0))
     return ret_type;
+  else if (TREE_CODE (TYPE_NAME (block_struct)) == TYPE_DECL
+	   && ((! DECL_NAME (TYPE_NAME (block_struct)))
+	       || (strncmp 
+		    (IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (block_struct))),
+		     "__Block_byref_", 14) != 0)))
+    return ret_type;
+  /* APPLE LOCAL end radar 6237086  */
 
   /* We've got the record for a __Byref_block_etc; go through the fields
      looking for one with the same name as the var_decl.  */
@@ -12504,6 +12749,35 @@
   return ret_type;
 }
 
+/* APPLE LOCAL begin radar 6237616  */
+/* Called from build_byref_var_location_expression, this function
+   checks to see if the starting location description is of type
+   DW_OP_regX (which, legally, cannot have anything added to it),
+   and if so, changes it to the equivalent DW_OP_bregX + 0, which
+   CAN legally have other stuff added to it.  */
+
+static void
+blocks_fixup_location_description (dw_loc_descr_ref *main_descr)
+{
+  dw_loc_descr_ref old_descr;
+  dw_loc_descr_ref new_descr;
+  enum dwarf_location_atom new_op;
+  int regno;
+  unsigned int offset = 0;
+
+  old_descr = *main_descr;
+
+  if (old_descr->dw_loc_opc >= DW_OP_reg0
+      && old_descr->dw_loc_opc <= DW_OP_reg31)
+    {
+      regno = old_descr->dw_loc_opc - DW_OP_reg0;
+      new_op = DW_OP_breg0 + regno;
+      new_descr = new_loc_descr (new_op, offset, 0);
+      *main_descr = new_descr;
+    }
+}
+/* APPLE LOCAL end radar 6237616  */
+
 /* This function is a helper function for the function below,
    add_block_byref_var_location_attribute.  See comments there
    for full description.  */
@@ -12516,6 +12790,12 @@
 {
   dw_loc_descr_ref temp_descr;
 
+  /* APPLE LOCAL begin radar 6237616  */
+  /* Make sure main_descr is legal, to start with.  */
+
+  blocks_fixup_location_description (main_descr);
+  /* APPLE LOCAL end radar 6237616  */
+
   /* If we started with a pointer to the __Block_byref... struct, then
      the first thing we need to do is dereference the pointer
      (DW_OP_deref).  */
@@ -12645,11 +12925,28 @@
   if (TREE_CODE (block_struct) != RECORD_TYPE)
     return false;
 
-  if ((! TYPE_NAME (block_struct))
-      || (! IDENTIFIER_POINTER (TYPE_NAME (block_struct)))
-      || strncmp (IDENTIFIER_POINTER (TYPE_NAME (block_struct)),
-		  "__Block_byref_", 14) != 0)
+  /* APPLE LOCAL begin radar 6237086  */
+  /* Look for a type name, and make sure it contains the __Block_byref_
+     substring.  */
+
+  if (! TYPE_NAME (block_struct))
+    return false;
+
+  if (TREE_CODE (TYPE_NAME (block_struct)) != IDENTIFIER_NODE
+      && TREE_CODE (TYPE_NAME (block_struct)) != TYPE_DECL)
+    return false;
+
+  if (TREE_CODE (TYPE_NAME (block_struct)) == IDENTIFIER_NODE
+      && (strncmp (IDENTIFIER_POINTER (TYPE_NAME (block_struct)),
+		   "__Block_byref_", 14) != 0))
+    return false;
+  else if (TREE_CODE (TYPE_NAME (block_struct)) == TYPE_DECL
+	   && ((! DECL_NAME (TYPE_NAME (block_struct)))
+	       || (strncmp 
+		    (IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (block_struct))),
+		     "__Block_byref_", 14) != 0)))
     return false;
+  /* APPLE LOCAL end radar 6237086  */
 
   /* Find the forwarding field and the variable field within
      the struct.  */
@@ -12668,7 +12965,7 @@
 		      var_name) == 0)
 	    var_field = temp_field;
 	  else if (strcmp (IDENTIFIER_POINTER (DECL_NAME (temp_field)),
-			   "forwarding") == 0)
+			   "__forwarding") == 0)
 	    forwarding_field = temp_field;
 	}
 
@@ -12825,14 +13122,26 @@
     {
       if (TREE_CODE (decl_type) == POINTER_TYPE)
 	decl_type = TREE_TYPE (decl_type);
+      /* APPLE LOCAL begin radar 6237086  */
       if (decl_type
 	  && TREE_CODE (decl_type) == RECORD_TYPE
-	  && TYPE_NAME (decl_type)
-	  && TREE_CODE (TYPE_NAME (decl_type)) == IDENTIFIER_NODE
-	  && IDENTIFIER_POINTER (TYPE_NAME (decl_type))
-	  && (strncmp (IDENTIFIER_POINTER (TYPE_NAME (decl_type)), 
-		       "__Block_byref_", 14) == 0))
-	  is_block_byref_var = true;
+	  && TYPE_NAME (decl_type))
+	{
+	  if (TREE_CODE (TYPE_NAME (decl_type)) == IDENTIFIER_NODE
+	      && strncmp (IDENTIFIER_POINTER (TYPE_NAME (decl_type)),
+			  "__Block_byref_", 14) == 0)
+	    is_block_byref_var = true;
+	  else if (TREE_CODE (TYPE_NAME (decl_type)) == TYPE_DECL
+		   && DECL_NAME (TYPE_NAME (decl_type))
+		   && IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl_type)))
+		   && (strncmp 
+		       (IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl_type))),
+			"__Block_byref_", 14) == 0))
+	    is_block_byref_var = true;
+	  else
+	    is_block_byref_var = false;
+	}
+      /* APPLE LOCAL end radar 6237086  */
     }
   /* APPLE LOCAL end radar 6048397 handle block byref variables  */
   if (origin != NULL)
@@ -13053,6 +13362,8 @@
 
       decls_for_scope (stmt, subr_die, depth);
       current_function_has_inlines = 1;
+      /* APPLE LOCAL radar 6275985 debug inlined section  */
+      add_inlined_section_entry (subr_die);
     }
   else
     /* We may get here if we're the outer block of function A that was
@@ -14846,6 +15157,8 @@
   pubname_table = VEC_alloc (pubname_entry, gc, 32);
   pubtype_table = VEC_alloc (pubname_entry, gc, 32);
   /* APPLE LOCAL end pubtypes, approved for 4.3 4535968  */
+  /* APPLE LOCAL radar 6275985 debug inlined section  */
+  debug_inlined_table = VEC_alloc (inlined_entry, gc, 32);
 
   /* Generate the initial DIE for the .debug section.  Note that the (string)
      value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
@@ -14879,6 +15192,12 @@
 				        SECTION_DEBUG, NULL);
 #endif
   /* APPLE LOCAL end pubtypes, approved for 4.3 4535968  */
+  /* APPLE LOCAL begin radar 6275985 debug inlined section  */
+#ifdef DEBUG_INLINED_SECTION
+  debug_inlined_section = get_section (DEBUG_INLINED_SECTION,
+				       SECTION_DEBUG, NULL);
+#endif
+  /* APPLE LOCAL end radar 6275985 debug inlined section  */
   debug_str_section = get_section (DEBUG_STR_SECTION,
 				   DEBUG_STR_SECTION_FLAGS, NULL);
   debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
@@ -15105,15 +15424,19 @@
 	s->refcount++;
 	/* Avoid unnecessarily putting strings that are used less than
 	   twice in the hash table.  */
-	if (s->refcount
-	    == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
+	/* APPLE LOCAL begin radar 6275985 debug inlined section  */
+	/* We always want function names to go into the hash table.  */
+	if ((s->refcount
+	     == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
+	    || s->is_fn_name)
 	  {
 	    void ** slot;
 	    slot = htab_find_slot_with_hash (debug_str_hash, s->str,
 					     htab_hash_string (s->str),
 					     INSERT);
-	    gcc_assert (*slot == NULL);
-	    *slot = s;
+	    if (*slot == NULL)
+	      *slot = s;
+	  /* APPLE LOCAL end radar 6275985 debug inlined section  */
 	  }
       }
 }
@@ -15402,6 +15725,17 @@
 #endif
   /* APPLE LOCAL end pubtypes, approved for 4.3 4535968  */
 
+  /* APPLE LOCAL begin radar 6275985 debug inlined section  */
+#ifdef DEBUG_INLINED_SECTION
+  /* Output debug section containing info about inlined subroutines  */
+  if (! VEC_empty (inlined_entry, debug_inlined_table))
+    {
+      switch_to_section (debug_inlined_section);
+      output_debug_inlined_section (debug_inlined_table);
+    }
+#endif
+  /* APPLE LOCAL end radar 6275985 debug inlined section  */
+
   /* Output the address range information.  We only put functions in the arange
      table, so don't write it out if we don't have any.  */
   if (fde_table_in_use)

Modified: llvm-gcc-4.2/trunk/gcc/function.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/function.c?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/function.c (original)
+++ llvm-gcc-4.2/trunk/gcc/function.c Mon Nov  3 01:33:15 2008
@@ -216,6 +216,8 @@
 static void do_clobber_return_reg (rtx, void *);
 static void do_use_return_reg (rtx, void *);
 static void set_insn_locators (rtx, int) ATTRIBUTE_UNUSED;
+/* APPLE LOCAL radar 6163705, Blocks prologues  */
+static rtx find_block_prologue_insns (void);
 
 /* Pointer to chain of `struct function' for containing functions.  */
 struct function *outer_function_chain;
@@ -5140,6 +5142,140 @@
 }
 #endif
 
+/* APPLE LOCAL begin radar 6163705, Blocks prologues  */
+
+/* The function should only be called for Blocks functions.
+   
+   On being called, the main instruction list for the Blocks function
+   may contain instructions for setting up the ref_decl and byref_decl
+   variables in the Block.  Those isns really need to go before the
+   function prologue note rather than after.  If such instructions are
+   present, they are identifiable by their source line number, which
+   will be one line preceding the declaration of the function.  If
+   they are present, there will also be a source line note instruction
+   for that line.
+
+   This function does a set of things:
+   - It finds the first such prologue insn.
+   - It finds the last such prologue insn.
+   - It changes the insn locator of all such prologue insns to
+     the prologue locator.
+   - It finds the source line note for the bogus location and
+     removes it.
+   - It decides if it is safe to place the prolgoue end note
+     after the last prologue insn it finds, and if so, returns
+     the last prologue insn (otherwise it returns NULL).
+   
+   This function makes the following checks to determine if it is
+   safe to move the prologue end note to just below the last
+   prologue insn it finds.  If ALL of the checks succeed then it
+   is safe.  If any check fails, this function returns NULL.  The
+   checks it makes are:
+   
+       - There were no INSN_P instructions that occurred before the
+         first prologue insn.
+       - If there are any non-prologue insns between the first & last
+         prologue insn, the non-prologue insns do not outnumber the
+	 prologue insns.
+       - The first prologue insn & the last prologue insn are in the
+         same basic block.
+*/
+
+static rtx
+find_block_prologue_insns (void)
+{
+  rtx first_prologue_insn = NULL;
+  rtx last_prologue_insn = NULL;
+  rtx line_number_note = NULL;
+  rtx tmp_insn;
+  int num_prologue_insns = 0;
+  int total_insns = 0;
+  int prologue_line = DECL_SOURCE_LINE (cfun->decl) - 1;
+  bool other_insns_before_prologue = false;
+  bool start_of_fnbody_found = false;
+
+  /* Go through all the insns and find the first prologue insn, the
+     last prologue insn, the source line location note, and whether or
+     not there are any "real" insns that occur before the first
+     prologue insn.  Re-set the insn locator for prologue insns to the
+     prologue locator.  */
+
+  for (tmp_insn = get_insns(); tmp_insn; tmp_insn = NEXT_INSN (tmp_insn))
+    {
+      if (INSN_P (tmp_insn))
+	{
+	  if (insn_line (tmp_insn) == prologue_line)
+	    {
+	      if (!first_prologue_insn)
+		first_prologue_insn = tmp_insn;
+	      num_prologue_insns++;
+	      last_prologue_insn = tmp_insn;
+	      INSN_LOCATOR (tmp_insn) = prologue_locator;
+	    }
+	  else if (!first_prologue_insn
+		   && start_of_fnbody_found)
+	    other_insns_before_prologue = true;
+	}
+      else if (NOTE_P (tmp_insn)
+	       && NOTE_LINE_NUMBER (tmp_insn) == NOTE_INSN_FUNCTION_BEG)
+	start_of_fnbody_found = true;
+      else if (NOTE_P (tmp_insn)
+	       && (XINT (tmp_insn, 5) == prologue_line))
+	line_number_note = tmp_insn;
+    }
+
+  /* If there were no prologue insns, return now.  */
+
+  if (!first_prologue_insn)
+    return NULL;
+
+  /* If the source location note for the line before the beginning of the
+     function was found, remove it.  */
+
+  if (line_number_note)
+    remove_insn (line_number_note);
+
+  /* If other real insns got moved above the prologue insns, we can't
+     pull out the prologue insns, so return now.  */
+
+  if (other_insns_before_prologue && (optimize > 0))
+    return NULL;
+
+  /* Count the number of insns between the first prologue insn and the
+     last prologue insn; also count the number of non-prologue insns
+     between the first prologue insn and the last prologue insn.  */
+
+  tmp_insn = first_prologue_insn;
+  while (tmp_insn != last_prologue_insn)
+    {
+      total_insns++;
+      tmp_insn = NEXT_INSN (tmp_insn);
+    }
+  total_insns++;
+
+  /* If more than half of the insns between the first & last prologue
+     insns are not prologue insns, then there is too much code that
+     got moved in between prologue insns (by optimizations), so we
+     will not try to pull it out.  */
+  
+  if ((num_prologue_insns * 2) <= total_insns)
+    return NULL;
+
+  /* Make sure all the prologue insns are within one basic block.
+     If the insns cross a basic block boundary, then there is a chance
+     that moving them will cause incorrect code, so don't do it.  */
+
+  gcc_assert (first_prologue_insn != NULL);
+  gcc_assert (last_prologue_insn != NULL);
+
+  if (BLOCK_FOR_INSN (first_prologue_insn) != 
+      BLOCK_FOR_INSN (last_prologue_insn))
+    return NULL;
+
+  return last_prologue_insn;
+}
+/* APPLE LOCAL end radar 6163705, Blocks prologues  */
+
 /* Generate the prologue and epilogue RTL if the machine supports it.  Thread
    this into place with notes indicating where the prologue ends and where
    the epilogue begins.  Update the basic block information when possible.  */
@@ -5163,13 +5299,24 @@
 #ifdef HAVE_prologue
   if (HAVE_prologue)
     {
+      /* APPLE LOCAL begin radar 6163705, Blocks prologues  */
+      rtx last_prologue_insn = NULL;
+
+      if (BLOCK_SYNTHESIZED_FUNC (cfun->decl))
+	last_prologue_insn = find_block_prologue_insns();
+      /* APPLE LOCAL end radar 6163705, Blocks prologues  */
+
       start_sequence ();
       seq = gen_prologue ();
       emit_insn (seq);
 
       /* Retain a map of the prologue insns.  */
       record_insns (seq, &prologue);
-      prologue_end = emit_note (NOTE_INSN_PROLOGUE_END);
+
+      /* APPLE LOCAL begin radar 6163705, Blocks prologues  */
+      if (!last_prologue_insn)
+	prologue_end = emit_note (NOTE_INSN_PROLOGUE_END);
+      /* APPLE LOCAL end radar 6163705, Blocks prologues  */
  
 #ifndef PROFILE_BEFORE_PROLOGUE
       /* Ensure that instructions are not moved into the prologue when
@@ -5190,7 +5337,11 @@
 
       insert_insn_on_edge (seq, single_succ_edge (ENTRY_BLOCK_PTR));
       inserted = 1;
-    }
+
+      /* APPLE LOCAL begin radar 6163705, Blocks prologues  */
+      if (last_prologue_insn)
+	emit_note_after (NOTE_INSN_PROLOGUE_END, last_prologue_insn);
+      /* APPLE LOCAL end radar 6163705, Blocks prologues  */    }
 #endif
 
   /* If the exit block has no non-fake predecessors, we don't need

Modified: llvm-gcc-4.2/trunk/gcc/gimplify.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/gimplify.c?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/gimplify.c (original)
+++ llvm-gcc-4.2/trunk/gcc/gimplify.c Mon Nov  3 01:33:15 2008
@@ -1148,8 +1148,9 @@
   tree result_decl, result;
 
   if (!ret_expr || TREE_CODE (ret_expr) == RESULT_DECL
-      /* APPLE LOCAL radar 6040305 - blocks */
-      || ret_expr == error_mark_node || cur_block)
+      /* APPLE LOCAL radar 6261552 */
+      /* code to check for cur_block is removed. */
+      || ret_expr == error_mark_node)
     return GS_ALL_DONE;
 
   if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (current_function_decl))))

Modified: llvm-gcc-4.2/trunk/gcc/ipa-type-escape.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/ipa-type-escape.c?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/ipa-type-escape.c (original)
+++ llvm-gcc-4.2/trunk/gcc/ipa-type-escape.c Mon Nov  3 01:33:15 2008
@@ -519,11 +519,22 @@
 /* Return true if PARENT is supertype of CHILD.  Both types must be
    known to be structures or unions. */
  
+/* APPLE LOCAL begin 6107012 */
+static struct pointer_set_t GTY(()) *parent_type_p_pset;
+/* APPLE LOCAL end 6107012 */
+
 static bool
 parent_type_p (tree parent, tree child)
 {
   int i;
   tree binfo, base_binfo;
+
+  /* APPLE LOCAL begin 6107012 */
+  /* Don't walk the same tree twice.  */
+  if (parent_type_p_pset && pointer_set_insert (parent_type_p_pset, parent))
+    return false;
+  /* APPLE LOCAL end 6107012 */
+
   if (TYPE_BINFO (parent)) 
     for (binfo = TYPE_BINFO (parent), i = 0;
 	 BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
@@ -643,8 +654,18 @@
   if (to_type == from_type)
     return CT_USELESS;
 
+  /* APPLE LOCAL 6107012 */
+  parent_type_p_pset = pointer_set_create ();
   if (parent_type_p (to_type, from_type)) return CT_UP;
+  /* APPLE LOCAL begin 6107012 */
+  pointer_set_destroy (parent_type_p_pset);
+  parent_type_p_pset = pointer_set_create ();
+  /* APPLE LOCAL end 6107012 */
   if (parent_type_p (from_type, to_type)) return CT_DOWN;
+  /* APPLE LOCAL begin 6107012 */
+  pointer_set_destroy (parent_type_p_pset);
+  parent_type_p_pset = (struct pointer_set_t *)0;
+  /* APPLE LOCAL end 6107012 */
   return CT_SIDEWAYS;
 }     
 

Modified: llvm-gcc-4.2/trunk/gcc/objc/objc-act.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/objc/objc-act.c?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/objc/objc-act.c (original)
+++ llvm-gcc-4.2/trunk/gcc/objc/objc-act.c Mon Nov  3 01:33:15 2008
@@ -141,6 +141,12 @@
 #endif
 /* APPLE LOCAL end radar 4531086 */
 
+/* APPLE LOCAL begin radar 6307941 */
+#ifndef OBJC2_ABI_DISPATCH
+#define OBJC2_ABI_DISPATCH 0
+#endif
+/* APPLE LOCAL end radar 6307941 */
+
 /* These need specifying.  */
 #ifndef OBJC_FORWARDING_STACK_OFFSET
 #define OBJC_FORWARDING_STACK_OFFSET 0
@@ -188,7 +194,8 @@
 /* Code generation.  */
 
 static tree objc_build_constructor (tree, tree);
-static tree build_objc_method_call (int, tree, tree, tree, tree);
+/* APPLE LOCAL radar 6307941 */
+static tree build_objc_method_call (int, tree, tree, tree, tree, tree);
 static tree get_proto_encoding (tree);
 static tree lookup_interface (tree);
 static tree objc_add_static_instance (tree, tree);
@@ -257,7 +264,8 @@
 static void build_v2_class_template (void);
 static void build_v2_protocol_template (void);
 static void build_message_ref_template (void);
-static tree build_v2_build_objc_method_call (int, tree, tree, tree, tree, bool);
+/* APPLE LOCAL radar 6307941 */
+static tree build_v2_build_objc_method_call (int, tree, tree, tree, tree, tree, bool);
 /* APPLE LOCAL radar 4695109 */
 static void build_v2_protocol_reference (tree);
 /* APPLE LOCAL radar 5153561 */
@@ -389,7 +397,8 @@
 #endif
 static int comp_proto_with_proto (tree, tree, int);
 /* APPLE LOCAL begin 4209854 */
-static tree get_arg_type_list (tree, int, int);
+/* APPLE LOCAL radar 6307941 */
+static tree get_arg_type_list (tree, tree, int, int);
 static tree objc_decay_parm_type (tree);
 /* APPLE LOCAL end 4209854 */
 static void objc_push_parm (tree);
@@ -753,16 +762,18 @@
   if (flag_next_runtime)
     {
       /* APPLE LOCAL begin ARM hybrid objc-2.0 */
-      bool use_hybrid_msgSend = (flag_objc_abi == 2
-				 && flag_objc_legacy_dispatch);
+      /* APPLE LOCAL radar 6307941 */
+      /* code removed. */
       TAG_GETCLASS = "objc_getClass";
       TAG_GETMETACLASS = "objc_getMetaClass";
       TAG_MSGSEND = "objc_msgSend";
-      TAG_MSGSENDSUPER = use_hybrid_msgSend ? "objc_msgSendSuper2"
-					    : "objc_msgSendSuper";
+      /* APPLE LOCAL begin radar 6307941 */
+      TAG_MSGSENDSUPER = flag_objc_abi==2 ? "objc_msgSendSuper2"
+					  : "objc_msgSendSuper";
       TAG_MSGSEND_STRET = "objc_msgSend_stret";
-      TAG_MSGSENDSUPER_STRET = use_hybrid_msgSend ? "objc_msgSendSuper2_stret"
-						  : "objc_msgSendSuper_stret";
+      TAG_MSGSENDSUPER_STRET = flag_objc_abi==2 ? "objc_msgSendSuper2_stret"
+						: "objc_msgSendSuper_stret";
+      /* APPLE LOCAL end radar 6307941 */
       /* APPLE LOCAL end ARM hybrid objc-2.0 */
       default_constant_string_class_name = "NSConstantString";
       /* APPLE LOCAL begin radar 4810609 */
@@ -1070,6 +1081,7 @@
 
 void
 objc_continue_implementation (void)
+
 {
   objc_ivar_chain
     = continue_class (objc_implementation_context);
@@ -1175,7 +1187,9 @@
 managed_objc_object_pointer (tree type)
 {
   return type && type != error_mark_node && POINTER_TYPE_P (type)
-	 && (objc_is_object_id (TREE_TYPE (type)) || TYPED_OBJECT (TREE_TYPE (type)));
+	 && (objc_is_object_id (TREE_TYPE (type)) || TYPED_OBJECT (TREE_TYPE (type))
+             /* APPLE LOCAL radar 6255671 */
+             || TREE_CODE (type) == BLOCK_POINTER_TYPE);
 }
 /* APPLE LOCAL end radar 5168496 */
 
@@ -1314,9 +1328,17 @@
 	      /* APPLE LOCAL begin radar 4855821 */
 	      if (!flag_objc_gc)
 		{
+                  /* APPLE LOCAL begin radar 6255671 */
 		  if (!property_assign)
-	            warning (0, "'assign' attribute (default) not appropriate for non-gc object property %qs",
-		         IDENTIFIER_POINTER (PROPERTY_NAME (property_decl)));
+                  {
+                    if (TREE_CODE (TREE_TYPE (property_decl)) == BLOCK_POINTER_TYPE)
+                      error ("assign attribute (default) not appropriate for non-gc object property %qs",
+                             IDENTIFIER_POINTER (PROPERTY_NAME (property_decl)));
+                    else
+                      warning (0, "assign attribute (default) not appropriate for non-gc object property %qs",
+                               IDENTIFIER_POINTER (PROPERTY_NAME (property_decl)));
+                  }
+                  /* APPLE LOCAL end radar 6255671 */
 		}
 	      /* APPLE LOCAL end radar 4855821 */
               else if (!property_assign)
@@ -1916,7 +1938,8 @@
          and in accordance with C99 rules we generate: type temp;
          (temp = rhs, [lhs Setter:temp], temp) */
       /* APPLE LOCAL begin radar 5279122 */
-      rhs = default_conversion (rhs);
+      /* APPLE LOCAL radar 6264448 */
+      /* rhs = default_conversion (rhs);  removed */
       temp = objc_create_named_tmp_var (TREE_TYPE (rhs), "prop");
       /* APPLE LOCAL end radar 5279122 */
       bind = build3 (BIND_EXPR, void_type_node, temp, NULL, NULL);
@@ -1925,6 +1948,12 @@
       comma_exp = build_modify_expr (temp, NOP_EXPR, rhs);
       comma_exp = build_compound_expr (comma_exp,
 		    objc_setter_func_call (receiver, prop_ident, temp));
+      /* APPLE LOCAL begin radar 6264448 */
+      /* conversion of 'temp' moved *after* it is passed ar argument to build
+         setter call. This is because its type must match the setter's argument
+         type. */
+      temp = default_conversion (temp);
+      /* APPLE LOCAL end radar 6264448 */
     }
   else
     {
@@ -2766,12 +2795,11 @@
 
   /* struct objc_method_list   *optional_instance_methods; */
   if (!optional_instance_meth)
-    /* LLVM LOCAL - begin NUL pointer */
+    /* APPLE LOCAL begin radar 6285794 */
     initlist = tree_cons (NULL_TREE,
-                          convert (objc_method_list_ptr,
-                                   build_int_cst (NULL_TREE, 0)),
+                          convert (objc_method_list_ptr, integer_zero_node),
                           initlist);
-    /* LLVM LOCAL - end NUL pointer */
+    /* APPLE LOCAL end radar 6285794 */
   else
     {
       expr = convert (objc_method_list_ptr, build_unary_op (ADDR_EXPR, 
@@ -2781,12 +2809,11 @@
 
   /* struct objc_method_list   *optional_class_methods; */
   if (!optional_class_meth)
-    /* LLVM LOCAL - begin NUL pointer */
+    /* APPLE LOCAL begin radar 6285794 */
     initlist = tree_cons (NULL_TREE,
-                          convert (objc_method_list_ptr,
-                                   build_int_cst (NULL_TREE, 0)),
+                          convert (objc_method_list_ptr, integer_zero_node),
                           initlist);
-    /* LLVM LOCAL - end NUL pointer */
+    /* APPLE LOCAL end radar 6285794 */
   else
     {
       expr = convert (objc_method_list_ptr, build_unary_op (ADDR_EXPR, 
@@ -2796,12 +2823,11 @@
 
   /* struct objc_prop_list     *instance_properties; */
   if (!instance_prop)
-    /* LLVM LOCAL - begin NUL pointer */
+    /* APPLE LOCAL begin radar 6285794 */
     initlist = tree_cons (NULL_TREE,
-                          convert (objc_prop_list_ptr,
-                                   build_int_cst (NULL_TREE, 0)),
+                          convert (objc_prop_list_ptr, integer_zero_node),
                           initlist);
-    /* LLVM LOCAL - end NUL pointer */
+    /* APPLE LOCAL end radar 6285794 */
   else
     {
       expr = convert (objc_prop_list_ptr, build_unary_op (ADDR_EXPR, 
@@ -2876,18 +2902,17 @@
   initlist = build_tree_list (NULL_TREE, build_int_cst (NULL_TREE, size));
 
   initlist = tree_cons (NULL_TREE,
-			(!weak_ivar_layout_tree ? build_int_cst (NULL_TREE, 0)
+			(!weak_ivar_layout_tree ? integer_zero_node
 					        : weak_ivar_layout_tree),
 			initlist);
 
   /* struct _prop_list_t *properties; */
   if (!property_list)
-    /* LLVM LOCAL - begin NUL pointer */
+    /* APPLE LOCAL begin radar 6285794 */
     initlist = tree_cons (NULL_TREE,
-                          convert (objc_prop_list_ptr,
-                                   build_int_cst (NULL_TREE, 0)),
+                          convert (objc_prop_list_ptr, integer_zero_node),
                           initlist);
-    /* LLVM LOCAL - end NUL pointer */
+    /* APPLE LOCAL end radar 6285794 */
   else
     {
       expr = convert (objc_prop_list_ptr,
@@ -3009,6 +3034,61 @@
 		       : INSTANCE_METHOD_DECL);
 }
 
+
+/* APPLE LOCAL begin radar 6307941 */
+/* Non-legacy dispatch is a performance optimization only. 
+   Using the "wrong" dispatch is not a correctness problem, 
+   assuming non-legacy dispatch is supported at all. 
+
+   SnowLeopard: only the selectors below are optimized by the runtime. 
+     Other selectors should use legacy dispatch to save memory.
+*/
+static const char * const nonlegacy_dispatched_selectors[] = {
+  "allocWithZone:",
+  "alloc",
+  "class",
+  "self",
+  "isKindOfClass:",
+  "respondsToSelector:",
+  "isFlipped",
+  "length",
+  "objectForKey:",
+  "count",
+  "objectAtIndex:",
+  "isEqualToString:",
+  "isEqual:",
+  "retain",
+  "release",
+  "autorelease",
+  "hash",
+  "addObject:",
+  "countByEnumeratingWithState:objects:count:",
+};
+
+static int
+objc_legacy_dispatched_selector_p (tree sel_name)
+{
+  gcc_assert (flag_objc_abi == 2);
+  gcc_assert (sel_name);
+  if (flag_objc_legacy_dispatch) 
+    return true;
+  if (OBJC2_ABI_DISPATCH)
+    /* Do this for Snow Leopard ot later only. */
+    return false;
+  else {
+    size_t i, count;
+    const char *sel_cname = IDENTIFIER_POINTER (sel_name);
+    count = sizeof(nonlegacy_dispatched_selectors) / sizeof(nonlegacy_dispatched_selectors[0]);
+    for (i = 0; i < count; i++) 
+    {
+      if (!strcmp (sel_cname, nonlegacy_dispatched_selectors[i]))
+        return false;
+    }
+  } 
+  return true;
+}
+/* APPLE LOCAL end radar 6307941 */
+
 tree
 objc_build_method_signature (tree rettype, tree selector,
 			     tree optparms, bool ellipsis)
@@ -3212,7 +3292,7 @@
   /* APPLE LOCAL begin radar 5676962 */
   tree t;
   int cv = 0;
-  /* LLVM LOCAL */
+  /* APPLE LOCAL radar 6285794 */
   struct lang_type ** pTypeLang = 0;
   /* APPLE LOCAL end radar 5676962 */
 
@@ -3615,7 +3695,8 @@
      APPLE LOCAL end 4175534  */
 
 bool
-objc_compare_types (tree ltyp, tree rtyp, int argno, tree callee)
+/* APPLE LOCAL radar 6231433 */
+objc_compare_types (tree ltyp, tree rtyp, int argno, tree callee, const char *message)
 {
   tree lcls, rcls, lproto, rproto;
   bool pointers_compatible;
@@ -3647,7 +3728,8 @@
       /* Return types must be covariant.  */
       if (!comptypes (TREE_TYPE (ltyp), TREE_TYPE (rtyp))
 	  && !objc_compare_types (TREE_TYPE (ltyp), TREE_TYPE (rtyp),
-				  argno, callee))
+				  /* APPLE LOCAL radar 6231433 */
+				  argno, callee, message))
       return false;
 
       /* Argument types must be contravariant.  */
@@ -3656,7 +3738,8 @@
 	{
 	  if (!comptypes (TREE_VALUE (rtyp), TREE_VALUE (ltyp))
 	      && !objc_compare_types (TREE_VALUE (rtyp), TREE_VALUE (ltyp),
-				      argno, callee))
+				      /* APPLE LOCAL radar 6231433 */
+				      argno, callee, message))
 	    return false;
       }
 
@@ -3791,8 +3874,10 @@
 	/* APPLE LOCAL end 4175534 */
         /* APPLE LOCAL begin radar 5839123 */
 	case -3:
-	  warning (0, "comparison of distinct Objective-C types %qT and %qT lacks a cast",
-                   orig_rtyp, orig_ltyp);
+	  /* APPLE LOCAL begin radar 6231433 */
+	  warning (0, "%s of distinct Objective-C types %qT and %qT lacks a cast",
+                   message, orig_rtyp, orig_ltyp);
+	  /* APPLE LOCAL end radar 6231433 */
 	  break;
 
 	case -2:
@@ -3823,16 +3908,16 @@
   return true;
 }
 
-/* APPLE LOCAL begin radar 4229905 */
+/* APPLE LOCAL begin radar 4229905 - radar 6131433 */
 /* This routine is similar to objc_compare_types except that function-pointers are
    excluded. This is because, caller assumes that common types are of (id, Object*)
    variety and calls objc_common_type to obtain a common type. There is no commonolty
    between two function-pointers in this regard. */
 
 bool
-objc_have_common_type (tree ltyp, tree rtyp, int argno, tree callee)
+objc_have_common_type (tree ltyp, tree rtyp, int argno, tree callee, const char *message)
 {
-  if (objc_compare_types (ltyp, rtyp, argno, callee))
+  if (objc_compare_types (ltyp, rtyp, argno, callee, message))
     {
       /* exclude function-pointer types. */
       do
@@ -3845,7 +3930,7 @@
     }
   return false;
 }
-/* APPLE LOCAL end radar 4229905 */
+/* APPLE LOCAL end radar 4229905 - radar 6131433 */
 
 /* Check if LTYP and RTYP have the same type qualifiers.  If either type
    lives in the volatilized hash table, ignore the 'volatile' bit when
@@ -4032,8 +4117,17 @@
 		  : xref_tag (RECORD_TYPE, type));
 	}
 	/* APPLE LOCAL end 4216500 */
-      else
+      /* APPLE LOCAL begin radar 6267049 */
+      else {
+        /* This can only happen because of bogus code. Note that in this
+	   path, protocols is not even considered. */
+	error ("qualified type is not a valid object");
+        /* Check further to see if protocol is valid. */
+        if (protocols)
+	  (void) lookup_and_install_protocols (protocols, false);
         return interface;
+      }
+      /* APPLE LOCAL end radar 6267049 */
     }
 
   if (protocols)
@@ -4210,6 +4304,10 @@
 #ifdef OBJCPLUS
   DECL_THIS_STATIC (var) = 1; /* squash redeclaration errors */
 #endif
+  /* APPLE LOCAL begin 6255801 */
+  /* Keep word alignment for metadata records.  */
+  DECL_USER_ALIGN (var) = 1;
+  /* APPLE LOCAL end 6255801 */
 }
 /* APPLE LOCAL end radar 4431864 */
 
@@ -5018,7 +5116,8 @@
 	= build_tree_list (fields,
 			   flag_next_runtime
 			   ? build_unary_op (ADDR_EXPR, string_class_decl, 0)
-			   : build_int_cst (NULL_TREE, 0));
+			   /* APPLE LOCAL radar 6285794 */
+			   : integer_zero_node);
       fields = TREE_CHAIN (fields);
       initlist = tree_cons (fields, build_unary_op (ADDR_EXPR, string, 1),
 			    initlist);
@@ -5206,7 +5305,8 @@
       if (static_instances_decl)
 	expr = build_unary_op (ADDR_EXPR, static_instances_decl, 0);
       else
-	expr = build_int_cst (NULL_TREE, 0);
+	/* APPLE LOCAL radar 6285794 */
+	expr = integer_zero_node;
 
       initlist = tree_cons (NULL_TREE, expr, initlist);
     }
@@ -5229,12 +5329,12 @@
   /* refs = { ..., _OBJC_SELECTOR_TABLE, ... } */
 
   if (flag_next_runtime || ! sel_ref_chain)
-    /* LLVM LOCAL - begin NUL pointer */
+    /* APPLE LOCAL begin radar 6285794 */
     initlist = tree_cons (NULL_TREE,
                           convert (build_pointer_type (objc_selector_type),
-                                   build_int_cst (NULL_TREE, 0)),
+                                   integer_zero_node),
                           initlist);
-    /* LLVM LOCAL - end NUL pointer */
+    /* APPLE LOCAL end radar 6285794 */
   else
     initlist
       = tree_cons (NULL_TREE,
@@ -5381,7 +5481,8 @@
   if (UOBJC_SYMBOLS_decl)
     expr = build_unary_op (ADDR_EXPR, UOBJC_SYMBOLS_decl, 0);
   else
-    expr = build_int_cst (NULL_TREE, 0);
+    /* APPLE LOCAL radar 6285794 */
+    expr = integer_zero_node;
   initlist = tree_cons (NULL_TREE, expr, initlist);
 
   return objc_build_constructor (type, nreverse (initlist));
@@ -5576,7 +5677,8 @@
 	}
 
       /* Output {..., NULL}.  */
-      initlist = tree_cons (NULL_TREE, build_int_cst (NULL_TREE, 0), initlist);
+      /* APPLE LOCAL radar 6285794 */
+      initlist = tree_cons (NULL_TREE, integer_zero_node, initlist);
 
       expr = objc_build_constructor (TREE_TYPE (decl), nreverse (initlist));
       finish_var_decl (decl, expr);
@@ -5584,7 +5686,8 @@
 	= tree_cons (NULL_TREE, build_unary_op (ADDR_EXPR, decl, 1), decls);
     }
 
-  decls = tree_cons (NULL_TREE, build_int_cst (NULL_TREE, 0), decls);
+  /* APPLE LOCAL radar 6285794 */
+  decls = tree_cons (NULL_TREE, integer_zero_node, decls);
   expr = objc_build_constructor (type, nreverse (decls));
   static_instances_decl = start_var_decl (type, "_OBJC_STATIC_INSTANCES");
   finish_var_decl (static_instances_decl, expr);
@@ -5881,11 +5984,14 @@
 			    ? objc_build_constructor
 			      (objc_selector_template,
 			       tree_cons (NULL_TREE,
-					  build_int_cst (NULL_TREE, 0),
+					  /* APPLE LOCAL radar 6285794 */
+					  integer_zero_node,
 					  tree_cons (NULL_TREE,
-						     build_int_cst (NULL_TREE, 0),
+						     /* APPLE LOCAL radar 6285794 */
+						     integer_zero_node,
 						     NULL_TREE)))
-			    : build_int_cst (NULL_TREE, 0), initlist);
+			    /* APPLE LOCAL radar 6285794 */
+			    : integer_zero_node, initlist);
       initlist = objc_build_constructor (TREE_TYPE (UOBJC_SELECTOR_TABLE_decl),
 					 nreverse (initlist));
       finish_var_decl (UOBJC_SELECTOR_TABLE_decl, initlist);
@@ -5909,7 +6015,8 @@
       return add_objc_string (encoding, meth_var_types);
     }
   else
-    return build_int_cst (NULL_TREE, 0);
+    /* APPLE LOCAL radar 6285794 */
+    return integer_zero_node;
 }
 
 /* sel_ref_chain is a list whose "value" fields will be instances of
@@ -9655,17 +9762,16 @@
       /* static struct objc_protocol _OBJC_PROTOCOL_<mumble>; */
       protocol_name_expr = add_objc_string (PROTOCOL_NAME (p), class_names);
 
-      /* LLVM LOCAL - begin NUL pointer */
       if (refs_decl)
 	refs_expr = convert (build_pointer_type (build_pointer_type
 						 (objc_protocol_template)),
 			     build_unary_op (ADDR_EXPR, refs_decl, 0));
       else
+      /* APPLE LOCAL begin radar 6285794 */
         refs_expr =
           convert (build_pointer_type (build_pointer_type (objc_protocol_template)),
-                   build_int_cst (NULL_TREE, 0));
-      /* LLVM LOCAL - end NUL pointer */
-
+                   integer_zero_node);
+      /* APPLE LOCAL end radar 6285794 */
       /* APPLE LOCAL begin radar 4585769 - Objective-C 1.0 extensions */
       save_objc_implementation_context = objc_implementation_context;
       objc_implementation_context = p;
@@ -9739,11 +9845,12 @@
   /* APPLE LOCAL begin ObjC new abi */
   /* APPLE LOCAL begin radar 4533974 - ObjC new protocol */
   /* APPLE LOCAL begin radar 4533974 - ObjC newprotocol - radar 4695109 */
-  /* LLVM LOCAL - begin NUL pointer */
   if (newabi)
     {
       /* 'isa' is NULL in the new ObjC abi */
-      expr = convert (objc_object_type, build_int_cst (NULL_TREE, 0));
+      /* APPLE LOCAL begin radar 6285794 */
+      expr = convert (objc_object_type, integer_zero_node);
+      /* APPLE LOCAL end radar 6285794 */
     }
   /* APPLE LOCAL end radar 4533974 - ObjC newprotocol - radar 4695109 */
   /* APPLE LOCAL begin radar 4585769 - Objective-C 1.0 extensions */
@@ -9751,19 +9858,20 @@
   else
     {
       if (!objc_protocol_or_opt_ins_meth)
+        /* APPLE LOCAL begin radar 6285794 */
         {
           if (!objc_protocol_extension_template)
             build_objc_protocol_extension_template ();    
           
           expr =
             convert (build_pointer_type (objc_protocol_extension_template),
-                     build_int_cst (NULL_TREE, 0));
+                     integer_zero_node);
         }
+        /* APPLE LOCAL end radar 6285794 */
       else
 	expr = convert (build_pointer_type (objc_protocol_extension_template),
 			build_unary_op (ADDR_EXPR, objc_protocol_or_opt_ins_meth, 0));	
     }
-  /* LLVM LOCAL - end NUL pointer */
   /* APPLE LOCAL end radar 4585769 - Objective-C 1.0 extensions */
 
   initlist = tree_cons (NULL_TREE, expr, initlist);
@@ -9773,12 +9881,12 @@
   initlist = tree_cons (NULL_TREE, protocol_list, initlist);
 
   if (!instance_methods)
-    /* LLVM LOCAL - begin NUL pointer */
+    /* APPLE LOCAL begin radar 6285794 */
     initlist = tree_cons (NULL_TREE,
                           convert (objc_method_proto_list_ptr,
-                                   build_int_cst (NULL_TREE, 0)),
+                                   integer_zero_node),
                           initlist);
-    /* LLVM LOCAL - end NUL pointer */
+    /* APPLE LOCAL end radar 6285794 */
   else
     {
       expr = convert (objc_method_proto_list_ptr,
@@ -9787,12 +9895,12 @@
     }
 
   if (!class_methods)
-    /* LLVM LOCAL - begin NUL pointer */
+    /* APPLE LOCAL begin radar 6285794 */
     initlist = tree_cons (NULL_TREE,
                           convert (objc_method_proto_list_ptr,
-                                   build_int_cst (NULL_TREE, 0)),
+                                   integer_zero_node),
                           initlist);
-  /* LLVM LOCAL - end NUL pointer */
+    /* APPLE LOCAL end radar 6285794 */
   else
     {
       expr = convert (objc_method_proto_list_ptr,
@@ -9805,12 +9913,12 @@
     {
       /* APPLE LOCAL begin radar 4695109 */
       if (!objc_protocol_or_opt_ins_meth)
-        /* LLVM LOCAL - begin NUL pointer */
+        /* APPLE LOCAL begin radar 6285794 */
         initlist = tree_cons (NULL_TREE,
                               convert (objc_method_proto_list_ptr,
-                                       build_int_cst (NULL_TREE, 0)),
+                                       integer_zero_node),
                               initlist);
-        /* LLVM LOCAL - end NUL pointer */
+        /* APPLE LOCAL end radar 6285794 */
       else
 	{
 	  expr = convert (objc_method_proto_list_ptr,
@@ -9818,12 +9926,12 @@
 	  initlist = tree_cons (NULL_TREE, expr, initlist);
 	}
       if (!opt_cls_meth)
-        /* LLVM LOCAL - begin NUL pointer */
+        /* APPLE LOCAL begin radar 6285794 */
         initlist = tree_cons (NULL_TREE,
                               convert (objc_method_proto_list_ptr,
-                                       build_int_cst (NULL_TREE, 0)),
+                                       integer_zero_node),
                               initlist);
-        /* LLVM LOCAL - end NUL pointer */
+        /* APPLE LOCAL end radar 6285794 */
       else
 	{
 	  expr = convert (objc_method_proto_list_ptr,
@@ -9832,12 +9940,12 @@
 	}
       /* APPLE LOCAL end radar 4695109 */
       if (!property_list)
-        /* LLVM LOCAL - begin NUL pointer */
+        /* APPLE LOCAL begin radar 6285794 */
         initlist = tree_cons (NULL_TREE,
                               convert (objc_prop_list_ptr,
-                                       build_int_cst (NULL_TREE, 0)),
+                                       integer_zero_node),
                               initlist);
-        /* LLVM LOCAL - end NUL pointer */
+        /* APPLE LOCAL end radar 6285794 */
       else
 	{
 	  expr = convert (objc_prop_list_ptr,
@@ -9851,7 +9959,7 @@
 	      TREE_INT_CST_LOW (TYPE_SIZE_UNIT (objc_v2_protocol_template)));
       initlist = tree_cons (NULL_TREE, expr, initlist);
       /* const uint32_t flags; = 0 */
-      initlist = tree_cons (NULL_TREE, build_int_cst (NULL_TREE, 0), initlist);
+      initlist = tree_cons (NULL_TREE, integer_zero_node, initlist);
       /* APPLE LOCAL end radar 5192466 */
     }
   /* APPLE LOCAL end C* property metadata (Radar 4498373) */
@@ -10925,12 +11033,12 @@
 			  ivar);
       else
 	/* Unnamed bit-field ivar (yuck).  */
-        /* LLVM LOCAL - begin NUL pointer */
+        /* APPLE LOCAL begin radar 6285794 */
         ivar = tree_cons (NULL_TREE,
                           convert (string_type_node,
-                                   build_int_cst (NULL_TREE, 0)),
+                                   integer_zero_node),
                           ivar);
-        /* LLVM LOCAL - end NUL pointer */
+        /* APPLE LOCAL end radar 6285794 */
 
       /* Set type.  */
       encode_field_decl (field_decl,
@@ -11498,12 +11606,12 @@
                                       meth_var_types),
                      eltlist);
 
-      /* LLVM LOCAL begin */
+      /* APPLE LOCAL begin radar 6285794 */
       eltlist = tree_cons (NULL_TREE, 
                            convert (objc_method_list_ptr,
-                                    build_int_cst (NULL_TREE, 0)), 
+                                    integer_zero_node),
                            eltlist);
-      /* LLVM LOCAL end */
+      /* APPLE LOCAL end radar 6285794 */
       initlist
         = tree_cons (NULL_TREE,
                      objc_build_constructor (type, nreverse (eltlist)),
@@ -11621,7 +11729,8 @@
       size++;
 
   /* Build initializer.  */
-  initlist = tree_cons (NULL_TREE, build_int_cst (NULL_TREE, 0), NULL_TREE);
+  /* APPLE LOCAL radar 6285794 */
+  initlist = tree_cons (NULL_TREE, integer_zero_node, NULL_TREE);
   e = build_int_cst (build_pointer_type (objc_protocol_template), size);
   initlist = tree_cons (NULL_TREE, e, initlist);
 
@@ -11674,12 +11783,12 @@
   initlist = tree_cons (NULL_TREE, class_name, initlist);
 
   if (!instance_methods)
-    /* LLVM LOCAL - begin NUL pointer */
+    /* APPLE LOCAL begin radar 6285794 */
     initlist = tree_cons (NULL_TREE,
                           convert (objc_method_list_ptr,
-                                   build_int_cst (NULL_TREE, 0)),
+                                   integer_zero_node),
                           initlist);
-    /* LLVM LOCAL - end NUL pointer */
+    /* APPLE LOCAL end radar 6285794 */
   else
     {
       expr = convert (objc_method_list_ptr,
@@ -11687,12 +11796,12 @@
       initlist = tree_cons (NULL_TREE, expr, initlist);
     }
   if (!class_methods)
-    /* LLVM LOCAL - begin NUL pointer */
+    /* APPLE LOCAL begin radar 6285794 */
     initlist = tree_cons (NULL_TREE,
                           convert (objc_method_list_ptr,
-                                   build_int_cst (NULL_TREE, 0)),
+                                   integer_zero_node),
                           initlist);
-    /* LLVM LOCAL - end NUL pointer */
+    /* APPLE LOCAL end radar 6285794 */
   else
     {
       expr = convert (objc_method_list_ptr,
@@ -11701,7 +11810,7 @@
     }
 
   /* protocol_list = */
-  /* LLVM LOCAL - begin NUL pointer */
+  /* APPLE LOCAL begin radar 6285794 */
   {
     tree protocol_list_ptr =
       (abi_v2) ? build_pointer_type (objc_v2_protocol_template)
@@ -11710,7 +11819,7 @@
     if (!protocol_list)
       initlist = tree_cons (NULL_TREE, 
                             convert (protocol_list_ptr,
-                                     build_int_cst (NULL_TREE, 0)),
+                                     integer_zero_node),
                             initlist);
     else
       {
@@ -11720,7 +11829,7 @@
         initlist = tree_cons (NULL_TREE, expr, initlist);
       }
   }
-  /* LLVM LOCAL - end NUL pointer */
+  /* APPLE LOCAL end radar 6285794 */
   /* APPLE LOCAL begin radar 4585769 - Objective-C 1.0 extensions */
   if (!abi_v2)
     {
@@ -11732,12 +11841,12 @@
   /* APPLE LOCAL begin C* property metadata (Radar 4498373) */
   /* struct _objc_property_list *instance_properties; */
   if (!property_list)
-    /* LLVM LOCAL - begin NUL pointer */
+    /* APPLE LOCAL begin radar 6285794 */
     initlist = tree_cons (NULL_TREE, 
                           convert (objc_prop_list_ptr,
-                                   build_int_cst (NULL_TREE, 0)),
+                                   integer_zero_node),
                           initlist);
-    /* LLVM LOCAL - end NUL pointer */
+    /* APPLE LOCAL end radar 6285794 */
   else
     {
       expr = convert (objc_prop_list_ptr,
@@ -11804,12 +11913,12 @@
 
   /* objc_ivar_list = */
   if (!ivar_list)
-    /* LLVM LOCAL - begin NUL pointer */
+    /* APPLE LOCAL begin radar 6285794 */
     initlist = tree_cons (NULL_TREE, 
                           convert (objc_ivar_list_ptr,
-                                   build_int_cst (NULL_TREE, 0)),
+                                   integer_zero_node),
                           initlist);
-    /* LLVM LOCAL - end NUL pointer */
+    /* APPLE LOCAL end radar 6285794 */
   else
     {
       expr = convert (objc_ivar_list_ptr,
@@ -11819,12 +11928,12 @@
 
   /* objc_method_list = */
   if (!dispatch_table)
-    /* LLVM LOCAL - begin NUL pointer */
+    /* APPLE LOCAL begin radar 6285794 */
     initlist = tree_cons (NULL_TREE,
                           convert (objc_method_list_ptr,
-                                   build_int_cst (NULL_TREE, 0)),
+                                   integer_zero_node),
                           initlist);
-    /* LLVM LOCAL - end NUL pointer */
+    /* APPLE LOCAL end radar 6285794 */
   else
     {
       expr = convert (objc_method_list_ptr,
@@ -11832,7 +11941,7 @@
       initlist = tree_cons (NULL_TREE, expr, initlist);
     }
 
-  /* LLVM LOCAL - begin NUL pointer */
+  /* APPLE LOCAL begin radar 6285794 */
   if (flag_next_runtime)
     /* method_cache = */
     initlist = tree_cons (NULL_TREE,
@@ -11840,20 +11949,20 @@
                                    (xref_tag (RECORD_TYPE,
                                               get_identifier
                                               ("objc_cache"))),
-                                   build_int_cst (NULL_TREE, 0)),
+                                   integer_zero_node),
                           initlist);
   else
     {
       tree null_objc_class_ptr = 
         convert (build_pointer_type (objc_class_template),
-                 build_int_cst (NULL_TREE, 0));
+                 integer_zero_node);
  
       /* dtable = */
       initlist = tree_cons (NULL_TREE,
                             convert (build_pointer_type (xref_tag (RECORD_TYPE,
                                                                    get_identifier
                                                                    ("sarray"))),
-                                     build_int_cst (NULL_TREE, 0)),
+                                     integer_zero_node),
                             initlist);
  
       /* subclass_list = */
@@ -11862,10 +11971,10 @@
       /* sibling_class = */
       initlist = tree_cons (NULL_TREE, null_objc_class_ptr, initlist);
     }
-  /* LLVM LOCAL - end NUL pointer */
- 
+    /* APPLE LOCAL end radar 6285794 */
+
   /* protocol_list = */
-  /* LLVM LOCAL - begin NUL pointer */
+  /* APPLE LOCAL begin radar 6285794 */
   {
     tree objc_protocol_ptr_ptr =
       build_pointer_type (build_pointer_type (objc_protocol_template));
@@ -11873,7 +11982,7 @@
     if (!protocol_list)
       initlist = tree_cons (NULL_TREE,
                             convert (objc_protocol_ptr_ptr,
-                                     build_int_cst (NULL_TREE, 0)),
+                                     integer_zero_node),
                             initlist);
     else
       {
@@ -11882,34 +11991,34 @@
         initlist = tree_cons (NULL_TREE, expr, initlist);
       }
   }
-  /* LLVM LOCAL - end NUL pointer */
+  /* APPLE LOCAL end radar 6285794 */
 
   /* APPLE LOCAL begin radar 4585769 - Objective-C 1.0 extensions */
   if (flag_next_runtime)
     {
       /* const char *ivar_layout; */
       if (IS_CLS_META (status)) /* Meta Class ? */
- 	/* LLVM LOCAL - begin NUL pointer */
+ 	/* APPLE LOCAL begin radar 6285794 */
         initlist = tree_cons (NULL_TREE,
                               convert (string_type_node,
-                                       build_int_cst (NULL_TREE, 0)),
+                                       integer_zero_node),
                               initlist);
- 	/* LLVM LOCAL - end NUL pointer */
+ 	/* APPLE LOCAL end radar 6285794 */
       else
 	{
 	  tree ivar_layout = objc_build_ivar_layout (true);
 	  if (!ivar_layout)
-            /* LLVM LOCAL - begin NUL pointer */
+            /* APPLE LOCAL begin radar 6285794 */
             initlist = tree_cons (NULL_TREE,
                                   convert (string_type_node,
-                                           build_int_cst (NULL_TREE, 0)),
+                                           integer_zero_node),
                                   initlist);
- 	    /* LLVM LOCAL - end NUL pointer */
+ 	    /* APPLE LOCAL end radar 6285794 */
 	  else
 	    initlist = tree_cons (NULL_TREE, ivar_layout, initlist);
 	}
       /* struct _objc_class_ext *ext; */
-      /* LLVM LOCAL - begin NUL pointer */
+      /* APPLE LOCAL begin radar 6285794 */
       if (!objc_class_ext_template)
         build_objc_class_ext_template ();
 
@@ -11920,7 +12029,7 @@
         if (!objc_class_ext)
           initlist = tree_cons (NULL_TREE,
                                 convert (objc_class_ext_ptr,
-                                         build_int_cst (NULL_TREE, 0)),
+                                         integer_zero_node),
                                 initlist);
         else
           {
@@ -11929,11 +12038,11 @@
             initlist = tree_cons (NULL_TREE, expr, initlist);
           }
       }
-      /* LLVM LOCAL - end NUL pointer */
+      /* APPLE LOCAL end radar 6285794 */
     }
   else
     /* gc_object_type = NULL */
-    /* LLVM LOCAL - NUL pointer */
+    /* APPLE LOCAL radar 6285794 - NUL pointer */
     initlist = tree_cons (NULL_TREE, null_pointer_node, initlist);
   /* APPLE LOCAL end radar 4585769 - Objective-C 1.0 extensions */
 
@@ -12098,19 +12207,19 @@
   if (cache)
     initlist = tree_cons (NULL_TREE, cache, initlist);
   else
-    /* LLVM LOCAL - NUL pointer */
+    /* APPLE LOCAL radar 6285794 - NUL pointer */
     initlist = tree_cons (NULL_TREE, null_pointer_node, initlist);
 
   /* vtable */
   if (vtable)
     initlist = tree_cons (NULL_TREE, vtable, initlist);
   else
-    /* LLVM LOCAL - begin NUL pointer */
+    /* APPLE LOCAL begin radar 6285794 */
     initlist = tree_cons (NULL_TREE,
                           convert (build_pointer_type (objc_imp_type),
-                                   build_int_cst (NULL_TREE, 0)),
+                                   integer_zero_node),
                           initlist);
-    /* LLVM LOCAL - end NUL pointer */
+    /* APPLE LOCAL end radar 6285794 */
 
   /* ro */
   initlist = tree_cons (NULL_TREE, ro, initlist);
@@ -12154,12 +12263,12 @@
   /* APPLE LOCAL begin radar 4695101 */
   /* ivarLayout */
   if (!ivarLayout)
-    /* LLVM LOCAL - begin NUL pointer */
+    /* APPLE LOCAL begin radar 6285794 */
     initlist = tree_cons (NULL_TREE,
                           convert (string_type_node,
-                                   build_int_cst (NULL_TREE, 0)),
+                                   integer_zero_node),
                           initlist);
-    /* LLVM LOCAL - end NUL pointer */
+    /* APPLE LOCAL end radar 6285794 */
   else
     initlist = tree_cons (NULL_TREE, ivarLayout, initlist);
   /* APPLE LOCAL end radar 4695101 */
@@ -12169,12 +12278,12 @@
 
   /* baseMethods */
   if (!baseMethods)
-    /* LLVM LOCAL - begin NUL pointer */
+    /* APPLE LOCAL begin radar 6285794 */
     initlist = tree_cons (NULL_TREE,
                           convert (objc_method_list_ptr,
-                                   build_int_cst (NULL_TREE, 0)),
+                                   integer_zero_node),
                           initlist);
-    /* LLVM LOCAL - end NUL pointer */
+    /* APPLE LOCAL end radar 6285794 */
   else
     {
       expr = convert (objc_method_list_ptr,
@@ -12183,7 +12292,7 @@
     }
 
   /* baseProtocols */
-  /* LLVM LOCAL - begin NUL pointer */
+  /* APPLE LOCAL begin radar 6285794 */
   {
     tree protocol_list_t_p =
       build_pointer_type (xref_tag (RECORD_TYPE, 
@@ -12192,7 +12301,7 @@
     if (!baseProtocols)
       initlist = tree_cons (NULL_TREE,
                             convert (protocol_list_t_p,
-                                     build_int_cst (NULL_TREE, 0)),
+                                     integer_zero_node),
                             initlist);
     else
       {
@@ -12201,16 +12310,16 @@
         initlist = tree_cons (NULL_TREE, expr, initlist);
       }
   }
-  /* LLVM LOCAL - end NUL pointer */
+  /* APPLE LOCAL end radar 6285794 */
 
   /* ivars */
   if (!ivars)
-    /* LLVM LOCAL - begin NUL pointer */
+    /* APPLE LOCAL begin radar 6285794 */
     initlist = tree_cons (NULL_TREE,
                           convert (objc_v2_ivar_list_ptr,
-                                   build_int_cst (NULL_TREE, 0)),
+                                   integer_zero_node),
                           initlist);
-    /* LLVM LOCAL - end NUL pointer */
+    /* APPLE LOCAL end radar 6285794 */
   else
     {
       expr = convert (objc_v2_ivar_list_ptr,
@@ -12221,12 +12330,12 @@
   /* APPLE LOCAL begin radar 4695101 */
   /* weakIvarLayout */
   if (!weakIvarLayout)
-    /* LLVM LOCAL - begin NUL pointer */
+    /* APPLE LOCAL begin radar 6285794 */
     initlist = tree_cons (NULL_TREE,
                           convert (string_type_node,
-                                   build_int_cst (NULL_TREE, 0)),
+                                   integer_zero_node),
                           initlist);
-    /* LLVM LOCAL - end NUL pointer */
+    /* APPLE LOCAL end radar 6285794 */
   else
     initlist = tree_cons (NULL_TREE, weakIvarLayout, initlist);
   /* APPLE LOCAL end radar 4695101 */
@@ -12234,12 +12343,12 @@
   /* APPLE LOCAL begin C* property metadata (Radar 4498373) */
   /* property list */
   if (!property_list)
-    /* LLVM LOCAL - begin NUL pointer */
+    /* APPLE LOCAL begin radar 6285794 */
     initlist = tree_cons (NULL_TREE,
                           convert (objc_prop_list_ptr,
-                                   build_int_cst (NULL_TREE, 0)),
+                                   integer_zero_node),
                           initlist);
-    /* LLVM LOCAL - end NUL pointer */
+    /* APPLE LOCAL end radar 6285794 */
   else
     {
       expr = convert (objc_prop_list_ptr,
@@ -12315,17 +12424,36 @@
       /* APPLE LOCAL begin radar 4695109 */
       /* APPLE LOCAL begin - LLVM radar 5476262 */
 #ifdef ENABLE_LLVM
-      /* LLVM LOCAL - add 'L' prefix */
-      sprintf (string, "L_OBJC_PROTOCOL_$_%s", 
-	       IDENTIFIER_POINTER (PROTOCOL_NAME (expr)));
+      if (flag_objc_abi == 2)
+        /* LLVM LOCAL - add 'l' prefix */
+        sprintf (string, "l_OBJC_PROTOCOL_$_%s", 
+                 IDENTIFIER_POINTER (PROTOCOL_NAME (expr)));
+      else
+          /* LLVM LOCAL - add 'L' prefix */
+          sprintf (string, "L_OBJC_PROTOCOL_$_%s", 
+                   IDENTIFIER_POINTER (PROTOCOL_NAME (expr)));
+
       expr = lookup_name (get_identifier(string));
+
       if (expr == NULL_TREE)
-        /* LLVM LOCAL - &string[1] because of 'L' prefix */
+        /* LLVM LOCAL - &string[1] because of '[Ll]' prefix */
 	expr = start_var_decl (objc_v2_protocol_template, &string[1]);
 #else
-      sprintf (string, "_OBJC_PROTOCOL_$_%s", 
-	       IDENTIFIER_POINTER (PROTOCOL_NAME (expr)));
-      expr = start_var_decl (objc_v2_protocol_template, string);
+      /* APPLE LOCAL begin radar 6255913 */
+      if (flag_objc_abi == 2)
+      {
+        sprintf (string, "l_OBJC_PROTOCOL_$_%s", 
+	         IDENTIFIER_POINTER (PROTOCOL_NAME (expr)));
+        expr = start_var_decl (objc_v2_protocol_template, string);
+	set_user_assembler_name (expr, string);
+      }
+      /* APPLE LOCAL end radar 6255913 */
+      else
+      {
+        sprintf (string, "_OBJC_PROTOCOL_$_%s", 
+	         IDENTIFIER_POINTER (PROTOCOL_NAME (expr)));
+        expr = start_var_decl (objc_v2_protocol_template, string);
+      }
 #endif
       /* APPLE LOCAL end - LLVM radar 5476262 */
       /* APPLE LOCAL end radar 4695109 */
@@ -12524,10 +12652,10 @@
       /* root class.  */
       root_expr = build_unary_op (ADDR_EXPR, metaclass_decl, 0);
       metaclass_superclass_expr = build_unary_op (ADDR_EXPR, class_decl, 0);
-      /* LLVM LOCAL - begin NUL pointer */
+      /* APPLE LOCAL begin radar 6285794 */
       class_superclass_expr = convert (build_pointer_type (objc_v2_class_template),
-                                       build_int_cst (NULL_TREE, 0));
-      /* LLVM LOCAL - end NUL pointer */
+                                       integer_zero_node);
+      /* APPLE LOCAL end radar 6285794 */
       flags |= 0x2; /* CLS_ROOT: it is also a root meta class */
     }
 
@@ -12735,13 +12863,13 @@
       super_expr = build_c_cast (cast_type, super_expr); /* cast! */
     }
   else
-    /* LLVM LOCAL - begin NUL pointer */
+    /* APPLE LOCAL begin radar 6285794 */
     {
       super_expr = convert (string_type_node,
-                            build_int_cst (NULL_TREE, 0));
+                            integer_zero_node);
       super_expr = build_c_cast (cast_type, super_expr); /* cast! */
     }
-    /* LLVM LOCAL - end NUL pointer */
+    /* APPLE LOCAL end radar 6285794 */
 
   root_expr = add_objc_string (my_root_id, class_names);
   root_expr = build_c_cast (cast_type, root_expr); /* cast! */
@@ -13051,7 +13179,9 @@
       /* hackery to make an obj method look like a function type. */
       tree rettype = TREE_TYPE (*node);
       TREE_TYPE (*node) = build_function_type (TREE_VALUE (rettype), 
-		       	    get_arg_type_list (*node, METHOD_REF, 0));
+			    /* APPLE LOCAL radar 6307941 */
+                            get_arg_type_list (METHOD_SEL_NAME (*node), 
+                                               *node, METHOD_REF, 0));
       decl_attributes (node, attributes, flags);
       METHOD_TYPE_ATTRIBUTES (*node) = TYPE_ATTRIBUTES (TREE_TYPE (*node));
       TREE_TYPE (*node) = rettype;
@@ -13070,7 +13200,8 @@
    arguments (i.e., beyond self and _cmd) shall be represented by `...'.  */
 
 static tree
-get_arg_type_list (tree meth, int context, int superflag)
+/* APPLE LOCAL radar 6307941 */
+get_arg_type_list (tree sel_name, tree meth, int context, int superflag)
 {
   tree arglist, akey;
 
@@ -13085,8 +13216,8 @@
   /* Selector type - will eventually change to `int'.  */
   /* APPLE LOCAL begin ObjC new abi */
   chainon (arglist, build_tree_list (NULL_TREE, flag_objc_abi == 2 
-				     /* APPLE LOCAL ARM hybrid objc-2.0 */
-						&& !flag_objc_legacy_dispatch
+				     /* APPLE LOCAL ARM hybrid objc-2.0 - radar 6307941 */
+                                     && !objc_legacy_dispatched_selector_p (sel_name)
 				     ? (superflag 
 					? objc_v2_super_selector_type 
 					: objc_v2_selector_type)
@@ -13654,8 +13785,8 @@
   /* APPLE LOCAL ObjC new abi */
   /* Code moved down */
   /* APPLE LOCAL begin ObjC new abi */
-  /* APPLE LOCAL ARM hybrid objc-2.0 */
-  if (flag_objc_abi == 2 && !flag_objc_legacy_dispatch)
+  /* APPLE LOCAL ARM hybrid objc-2.0 - radar 6307941 */
+  if (flag_objc_abi == 2 && !objc_legacy_dispatched_selector_p (sel_name))
     {
       tree ret_type;
       tree message_func_decl;
@@ -13725,9 +13856,10 @@
 
       /* (*_msg.messenger) (receiver, &_msg, ...); */
       retval = build_v2_build_objc_method_call (super, method_prototype,
-						    receiver, selector, 
-						    method_params,
-						    check_for_nil);
+						/* APPLE LOCAL radar 6307941 */
+                                                receiver, sel_name, selector, 
+                                                method_params,
+                                                check_for_nil);
     }
   else
     {
@@ -13741,7 +13873,8 @@
 /* APPLE LOCAL end radar 4359757 */
 
         retval = build_objc_method_call (super, method_prototype,
-				         receiver,
+					 /* APPLE LOCAL radar 6307941 */
+				         receiver, sel_name, 
 				         selector, method_params);
     }
   /* APPLE LOCAL end ObjC new abi */
@@ -13760,7 +13893,8 @@
 
 static tree
 build_objc_method_call (int super_flag, tree method_prototype,
-			tree lookup_object, tree selector,
+			/* APPLE LOCAL radar 6307941 */
+			tree lookup_object, tree sel_name, tree selector,
 			tree method_params)
 {
   tree sender = (super_flag ? umsg_super_decl :
@@ -13779,7 +13913,9 @@
        ? TREE_VALUE (TREE_TYPE (method_prototype))
        : objc_object_type);
   /* APPLE LOCAL begin radar 3803157 - objc attribute */
-  tree method_param_types = get_arg_type_list (method_prototype, METHOD_REF, super_flag);
+  /* APPLE LOCAL radar 6307941 */
+  tree method_param_types = get_arg_type_list (sel_name, method_prototype, 
+                                               METHOD_REF, super_flag);
   tree ftype = build_function_type (ret_type, method_param_types);
   tree sender_cast;
   tree method, t;
@@ -13856,9 +13992,9 @@
 
 static tree
 build_v2_build_objc_method_call (int super_flag, tree method_prototype,
-                        	     tree lookup_object, tree selector,
-                        	     tree method_params,
-				     bool check_for_nil)
+                                 tree lookup_object, tree sel_name, 
+                                 tree selector, tree method_params,
+                                 bool check_for_nil)
 {
   tree ret_val;
   tree sender, rcv_p, t;
@@ -13866,7 +14002,8 @@
     = (method_prototype
        ? TREE_VALUE (TREE_TYPE (method_prototype))
        : objc_object_type);
-  tree method_param_types = get_arg_type_list (method_prototype, 
+  /* APPLE LOCAL radar 6307941 */
+  tree method_param_types = get_arg_type_list (sel_name, method_prototype, 
 					       METHOD_REF, super_flag);
   /* APPLE LOCAL begin radar 3803157 - objc attribute */
   tree ftype = build_function_type (ret_type, method_param_types);
@@ -13936,8 +14073,12 @@
 
   /* static struct protocol_t  _OBJC_PROTOCOL_$<mumble>; */
 
-  proto_name = synth_id_with_class_suffix ("_OBJC_PROTOCOL_$", p);
-  decl = start_var_decl (objc_v2_protocol_template, proto_name);
+  /* APPLE LOCAL begin radar 6255913 */
+  proto_name = synth_id_with_class_suffix ("l_OBJC_PROTOCOL_$", p);
+  decl = create_hidden_decl (objc_v2_protocol_template, proto_name);
+  DECL_WEAK (decl) = 1;
+  set_user_assembler_name (decl, proto_name);
+  /* APPLE LOCAL end radar 6255913 */
   PROTOCOL_V2_FORWARD_DECL (p) = decl;
   /* APPLE LOCAL begin - LLVM radar 5476262 */
 #ifdef ENABLE_LLVM
@@ -14039,11 +14180,11 @@
 	refs_expr = convert (build_pointer_type (objc_v2_protocol_template),
 			     build_unary_op (ADDR_EXPR, refs_decl, 0));
       else
-	/* LLVM LOCAL - begin NUL pointer */
+	/* APPLE LOCAL begin radar 6285794 */
         refs_expr =
           convert (build_pointer_type (objc_v2_protocol_template),
-                   build_int_cst (NULL_TREE, 0));
-	/* LLVM LOCAL - end NUL pointer */
+                   integer_zero_node);
+	/* APPLE LOCAL end radar 6285794 */
 
       /* APPLE LOCAL begin radar 4695101 */
       /* Build table of list of properties for this protocol. */
@@ -15804,7 +15945,8 @@
         PROPERTY_READONLY (cl_prop) == boolean_true_node &&
         PROPERTY_READONLY (property) == boolean_true_node &&
         objc_compare_types (TREE_TYPE (cl_prop), TREE_TYPE (property), 
-                            -6, NULL_TREE))
+			    /* APPLE LOCAL radar 6231433 */
+                            -6, NULL_TREE, NULL))
       ;
     else
       warning (0, "property %qs type does not match %s %qs property type",
@@ -16724,6 +16866,27 @@
 }
 /* APPLE LOCAL end radar 4968128 */
 
+/* APPLE LOCAL begin radar 6017984 */
+/* This routine merges all methods declared in the protocol-list
+   into the current class. */
+static void
+objc_merge_protocol_methods (tree class, tree rproto_list)
+{
+  tree rproto;
+  for (rproto = rproto_list; rproto; rproto = TREE_CHAIN (rproto))
+    {
+      tree p = TREE_VALUE (rproto);
+      if (TREE_CODE (p) == PROTOCOL_INTERFACE_TYPE)
+        {
+	  objc_merge_methods (class, PROTOCOL_CLS_METHODS (p), '+');
+	  objc_merge_methods (class, PROTOCOL_NST_METHODS (p), '-');
+          /* Search in nested protocols also. */
+          objc_merge_proto_properties_in_class (class, PROTOCOL_LIST (p));
+        }
+    }
+}
+/* APPLE LOCAL end radar 6017984 */
+
 /* This is called once we see the "@end" in an interface/implementation.  */
 
 static void
@@ -17014,6 +17177,12 @@
               {
                 objc_merge_methods (primary, CLASS_NST_METHODS (class), '-');
                 objc_merge_methods (primary, CLASS_CLS_METHODS (class), '+');
+	        /* APPLE LOCAL begin radar 6017984 */
+		/* Just as we are adding anonymous category's methods to the
+		   primary class, must also add methods in anonymous category's protocols
+		   to the class as well, */
+		objc_merge_protocol_methods (primary, CLASS_PROTOCOL_LIST (class));
+	        /* APPLE LOCAL end radar 6017984 */
               } 
           }
         /* APPLE LOCAL end radar 4965989 */
@@ -17925,13 +18094,16 @@
       return 0;
     if (!objc_types_share_size_and_alignment (type1, type2))
       return 0;
-    if (strict == 1 && !objc_compare_types(type1, type2, -2, 0))
+    /* APPLE LOCAL radar 6231433 */
+    if (strict == 1 && !objc_compare_types(type1, type2, -2, 0, NULL))
       return 0;
   }
 
   /* Compare argument types.  */
-  for (type1 = get_arg_type_list (proto1, METHOD_REF, 0),
-       type2 = get_arg_type_list (proto2, METHOD_REF, 0);
+  /* APPLE LOCAL begin radar 6307941 */
+  for (type1 = get_arg_type_list (METHOD_SEL_NAME (proto1), proto1, METHOD_REF, 0),
+       type2 = get_arg_type_list (METHOD_SEL_NAME (proto2), proto2, METHOD_REF, 0);
+  /* APPLE LOCAL end radar 6307941 */
        type1 && type2;
        type1 = TREE_CHAIN (type1), type2 = TREE_CHAIN (type2))
     {
@@ -17941,7 +18113,8 @@
         if (!objc_types_share_size_and_alignment (TREE_VALUE (type1), TREE_VALUE (type2)))
           return 0;
         /* Note, order of type2 and type1 in argument call is intentional. */
-        if (strict == 1 && !objc_compare_types(TREE_VALUE (type2), TREE_VALUE (type1), -2, 0))
+	/* APPLE LOCAL radar 6231433 */
+        if (strict == 1 && !objc_compare_types(TREE_VALUE (type2), TREE_VALUE (type1), -2, 0, NULL))
           return 0;
       }
     }
@@ -18119,7 +18292,8 @@
 
   meth_type
     = build_function_type (ret_type,
-			   get_arg_type_list (method, METHOD_DEF, 0));
+		    	   /* APPLE LOCAL radar 6307941 */
+			   get_arg_type_list (METHOD_SEL_NAME (method), method, METHOD_DEF, 0));
   /* APPLE LOCAL radar 5839812 - location for synthesized methods  */
   objc_start_function (method_id, meth_type, NULL_TREE, parmlist, method);
 
@@ -19131,7 +19305,7 @@
 		  	build_index_type (build_int_cst (NULL_TREE, 2 - 1))));
    /* LLVM LOCAL */
 #endif
-  initlist = build_tree_list (NULL_TREE, build_int_cst (NULL_TREE, 0));
+  initlist = build_tree_list (NULL_TREE, integer_zero_node);
   initlist = tree_cons (NULL_TREE, build_int_cst (NULL_TREE, flags), initlist);
   initlist = objc_build_constructor (TREE_TYPE (decl), nreverse (initlist));
   TREE_TYPE (initlist) = TREE_TYPE (decl);
@@ -19431,11 +19605,11 @@
   constructor_fields = TYPE_FIELDS (fast_enum_state_type);
   /* __objcFastEnumerationState enumState = { 0 }; */
   *enumState_decl = objc_create_named_tmp_var (fast_enum_state_type, "cstar");
-  /* LLVM LOCAL begin */
+  /* APPLE LOCAL begin radar 6285794 */
   initlist = build_tree_list (constructor_fields, 
                               convert (TREE_TYPE(constructor_fields),
-                                       build_int_cst (NULL_TREE, 0)));
-  /* LLVM LOCAL end */
+                                       integer_zero_node));
+  /* APPLE LOCAL end radar 6285794 */
   init = objc_build_constructor (fast_enum_state_type, initlist);
   DECL_INITIAL (*enumState_decl) = init;
 
@@ -20006,7 +20180,8 @@
 #endif
 		        comparison_result = comptypes (ivar_type, property_type) != 1;
 		      if (comparison_result
-			  && !objc_compare_types (property_type, ivar_type, -5, NULL_TREE))
+			  /* APPLE LOCAL radar 6231433 */
+			  && !objc_compare_types (property_type, ivar_type, -5, NULL_TREE, NULL))
                       /* APPLE LOCAL end radar 6029624 */
 		      /* APPLE LOCAL end radar 5389292 */
 			{

Modified: llvm-gcc-4.2/trunk/gcc/stub-objc.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/stub-objc.c?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/stub-objc.c (original)
+++ llvm-gcc-4.2/trunk/gcc/stub-objc.c Mon Nov  3 01:33:15 2008
@@ -102,19 +102,23 @@
 
 bool
 objc_compare_types (tree ARG_UNUSED (ltyp), tree ARG_UNUSED (rtyp),
-		    int ARG_UNUSED (argno), tree ARG_UNUSED (callee))
+		    /* APPLE LOCAL begin radar 6231433 */
+		    int ARG_UNUSED (argno), tree ARG_UNUSED (callee),
+		    const char * ARG_UNUSED (message))
+		    /* APPLE LOCAL end radar 6231433 */
 {
   return false;
 }
 
-/* APPLE LOCAL begin radar 4229905 */
+/* APPLE LOCAL begin radar 4229905 - radar 6231433 */
 bool
 objc_have_common_type (tree ARG_UNUSED (ltyp), tree ARG_UNUSED (rtyp),
-		       int ARG_UNUSED (argno), tree ARG_UNUSED (callee))
+		       int ARG_UNUSED (argno), tree ARG_UNUSED (callee),
+		       const char * ARG_UNUSED (message))
 {
   return false;
 }
-/* APPLE LOCAL end radar 4229905 */
+/* APPLE LOCAL end radar 4229905 - radar 6231433 */
 
 void
 objc_volatilize_decl (tree ARG_UNUSED (decl))
@@ -592,7 +596,12 @@
 }
 bool block_requires_copying (tree exp)
 {
-  return TREE_CODE (TREE_TYPE (exp)) == BLOCK_POINTER_TYPE;
+  /* APPLE LOCAL begin radar 6175959 */
+  tree type = TREE_TYPE (exp);
+  return TREE_CODE (type) == BLOCK_POINTER_TYPE
+	 || (POINTER_TYPE_P (type) 
+	     && lookup_attribute ("NSObject", TYPE_ATTRIBUTES (type)));
+  /* APPLE LOCAL end radar 6175959 */
 }
 /* APPLE LOCAL end radar 5782740 - blocks */
 

Modified: llvm-gcc-4.2/trunk/gcc/tree-inline.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/tree-inline.c?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/tree-inline.c (original)
+++ llvm-gcc-4.2/trunk/gcc/tree-inline.c Mon Nov  3 01:33:15 2008
@@ -1278,14 +1278,15 @@
 	  var = modify_dest;
 	  use = NULL;
 
-    /* LLVM LOCAL begin */
+          /* LLVM LOCAL begin */
 #ifdef ENABLE_LLVM
-    /* The return node may not dominate all of its uses.  Because of this,
-       conservatively don't consider it for SSA form anymore.  */
-    if (TREE_CODE (var) == VAR_DECL)
-      DECL_GIMPLE_FORMAL_TEMP_P (var) = 0;
+          /* The return node may not dominate all of its uses.  Because of this,
+             conservatively don't consider it for SSA form anymore.  */
+          if (TREE_CODE (var) == VAR_DECL)
+            DECL_GIMPLE_FORMAL_TEMP_P (var) = 0;
 #endif
     /* LLVM LOCAL end */
+
 	  goto done;
 	}
     }

Modified: llvm-gcc-4.2/trunk/gcc/tree.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/tree.c?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/tree.c (original)
+++ llvm-gcc-4.2/trunk/gcc/tree.c Mon Nov  3 01:33:15 2008
@@ -5108,6 +5108,11 @@
 {
   tree t;
   
+  /* APPLE LOCAL begin radar 6300081  */
+  if (!generic_block_literal_struct_type)
+    generic_block_literal_struct_type = build_generic_block_struct_type ();
+  /* APPLE LOCAL end radar 6300081  */
+
   t = make_node (BLOCK_POINTER_TYPE);
 
   TREE_TYPE (t) = to_type;

Modified: llvm-gcc-4.2/trunk/gcc/tree.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/tree.h?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/tree.h (original)
+++ llvm-gcc-4.2/trunk/gcc/tree.h Mon Nov  3 01:33:15 2008
@@ -4850,7 +4850,10 @@
 extern void note_alternative_entry_points (void);
 /* APPLE LOCAL end CW asm blocks */
 
-/* APPLE LOCAL radar 6113240 */
-extern GTY(()) tree invoke_impl_ptr_type;
+/* APPLE LOCAL begin radar 6300081  */
+extern GTY(()) tree generic_block_literal_struct_type;
+
+extern tree build_generic_block_struct_type (void);
+/* APPLE LOCAL end radar 6300081  */
 
 #endif  /* GCC_TREE_H  */

Modified: llvm-gcc-4.2/trunk/gcc/varasm.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/varasm.c?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/varasm.c (original)
+++ llvm-gcc-4.2/trunk/gcc/varasm.c Mon Nov  3 01:33:15 2008
@@ -2974,7 +2974,12 @@
 
   /* Create a string containing the label name, in LABEL.  */
   labelno = const_labelno++;
-  ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
+  /* APPLE LOCAL begin radar 6243961 */
+  if (flag_writable_strings && TREE_CODE (exp) == STRING_CST)
+    ASM_GENERATE_INTERNAL_LABEL (label, "lC", labelno);
+  else
+    ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
+  /* APPLE LOCAL end radar 6243961 */
 
   /* We have a symbol name; construct the SYMBOL_REF and the MEM.  */
   if (use_object_blocks_p ())
@@ -3027,6 +3032,12 @@
   struct constant_descriptor_tree key;
   void **loc;
 
+  /* APPLE LOCAL begin radar 6243961 */
+  int save_flag_writable_strings = flag_writable_strings;
+  if (flag_writable_strings && TREE_CODE (exp) == STRING_CST 
+      && darwin_constant_cfstring_p (exp))
+    flag_writable_strings = 0;
+  /* APPLE LOCAL end radar 6243961 */
   /* Look up EXP in the table of constant descriptors.  If we didn't find
      it, create a new one.  */
   key.value = exp;
@@ -3042,6 +3053,8 @@
     }
 
   maybe_output_constant_def_contents (desc, defer);
+  /* APPLE LOCAL radar 6243961 */
+  flag_writable_strings = save_flag_writable_strings;
   return desc->rtl;
 }
 

Modified: llvm-gcc-4.2/trunk/gcc/version.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/version.c?rev=58599&r1=58598&r2=58599&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/version.c (original)
+++ llvm-gcc-4.2/trunk/gcc/version.c Mon Nov  3 01:33:15 2008
@@ -11,12 +11,12 @@
 /* APPLE LOCAL begin Apple version */
 #ifdef ENABLE_LLVM
 #ifdef LLVM_VERSION_INFO
-#define VERSUFFIX " (Based on Apple Inc. build 5623) (LLVM build " LLVM_VERSION_INFO ")"
+#define VERSUFFIX " (Based on Apple Inc. build 5627) (LLVM build " LLVM_VERSION_INFO ")"
 #else
-#define VERSUFFIX " (Based on Apple Inc. build 5623) (LLVM build)"
+#define VERSUFFIX " (Based on Apple Inc. build 5627) (LLVM build)"
 #endif
 #else
-#define VERSUFFIX " (Based on Apple Inc. build 5623)"
+#define VERSUFFIX " (Based on Apple Inc. build 5627)"
 #endif
 /* APPLE LOCAL end Apple version */
 





More information about the llvm-commits mailing list