[llvm-commits] [llvm-gcc-4.2] r58576 - in /llvm-gcc-4.2/trunk/gcc: cgraph.h cgraphunit.c cp/semantics.c tree-gimple.h tree-nested.c

Bill Wendling isanbard at gmail.com
Sun Nov 2 17:39:05 PST 2008


Author: void
Date: Sun Nov  2 19:39:05 2008
New Revision: 58576

URL: http://llvm.org/viewvc/llvm-project?rev=58576&view=rev
Log:
Lower nested functions to the structors. Reference to 'this' in a block must be looked up.

Modified:
    llvm-gcc-4.2/trunk/gcc/cgraph.h
    llvm-gcc-4.2/trunk/gcc/cgraphunit.c
    llvm-gcc-4.2/trunk/gcc/cp/semantics.c
    llvm-gcc-4.2/trunk/gcc/tree-gimple.h
    llvm-gcc-4.2/trunk/gcc/tree-nested.c

Modified: llvm-gcc-4.2/trunk/gcc/cgraph.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/cgraph.h?rev=58576&r1=58575&r2=58576&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/cgraph.h (original)
+++ llvm-gcc-4.2/trunk/gcc/cgraph.h Sun Nov  2 19:39:05 2008
@@ -302,6 +302,8 @@
 void cgraph_add_new_function (tree);
 
 /* In cgraphunit.c  */
+/* APPLE LOCAL radar 6305545 */
+void lower_if_nested_functions (tree);
 bool cgraph_assemble_pending_functions (void);
 bool cgraph_varpool_assemble_pending_decls (void);
 void cgraph_finalize_function (tree, bool);

Modified: llvm-gcc-4.2/trunk/gcc/cgraphunit.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/cgraphunit.c?rev=58576&r1=58575&r2=58576&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/cgraphunit.c (original)
+++ llvm-gcc-4.2/trunk/gcc/cgraphunit.c Sun Nov  2 19:39:05 2008
@@ -473,6 +473,19 @@
   node->lowered = true;
 }
 
+/* APPLE LOCAL begin radar 6305545 */
+/** lower_if_nested_functions - This routine is called from cplus side only.
+    Its purpose is to lower block helper (or any other nested function)
+    which may have been nested in a constructor or destructor. We have to
+    do this because structors are cloned and are not lowered themselves (which
+    is the only way to lower the nested functions). */
+void 
+lower_if_nested_functions (tree decl)
+{
+    lower_nested_functions (decl, true);
+}
+/* APPLE LOCAL end radar 6305545 */
+
 /* DECL has been parsed.  Take it, queue it, compile it at the whim of the
    logic in effect.  If NESTED is true, then our caller cannot stand to have
    the garbage collector run at the moment.  We would need to either create
@@ -497,7 +510,8 @@
   node->local.finalized = true;
   node->lowered = DECL_STRUCT_FUNCTION (decl)->cfg != NULL;
   if (node->nested)
-    lower_nested_functions (decl);
+    /* APPLE LOCAL radar 6305545 */
+    lower_nested_functions (decl, false);
   gcc_assert (!node->nested);
 
   /* If not unit at a time, then we need to create the call graph

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

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/cp/semantics.c (original)
+++ llvm-gcc-4.2/trunk/gcc/cp/semantics.c Sun Nov  2 19:39:05 2008
@@ -1930,6 +1930,18 @@
       error ("%<this%> is unavailable for static member functions");
       result = error_mark_node;
     }
+  /* APPLE LOCAL begin radar 6275956 */
+  else if (cur_block && current_function_decl 
+           && BLOCK_SYNTHESIZED_FUNC (current_function_decl))
+    {
+      result = lookup_name (this_identifier);
+      if (!result)
+	{
+	  error ("invalid use of %<this%> in a block");
+	  result = error_mark_node;
+	}
+    }
+  /* APPLE LOCAL end radar 6275956 */
   else
     {
       if (current_function_decl)
@@ -2988,7 +3000,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 */
 	      decl = build_byref_local_var_access (decl,
 						   DECL_NAME (orig_decl));
 	    }
@@ -3271,6 +3283,11 @@
      it.  */
   if (maybe_clone_body (fn))
     {
+      /* APPLE LOCAL begin radar 6305545 */
+	/* Must lower the nested functions which could be, among other
+           things, block helper functions. */
+        lower_if_nested_functions (fn);
+      /* APPLE LOCAL end radar 6305545 */
       /* We don't want to process FN again, so pretend we've written
 	 it out, even though we haven't.  */
       TREE_ASM_WRITTEN (fn) = 1;

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

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/tree-gimple.h (original)
+++ llvm-gcc-4.2/trunk/gcc/tree-gimple.h Sun Nov  2 19:39:05 2008
@@ -140,7 +140,8 @@
 extern tree omp_reduction_init (tree, tree);
 
 /* In tree-nested.c.  */
-extern void lower_nested_functions (tree);
+/* APPLE LOCAL radar 6305545 */
+extern void lower_nested_functions (tree, bool);
 extern void insert_field_into_struct (tree, tree);
 
 /* Convenience routines to walk all statements of a gimple function.

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

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/tree-nested.c (original)
+++ llvm-gcc-4.2/trunk/gcc/tree-nested.c Sun Nov  2 19:39:05 2008
@@ -2221,7 +2221,8 @@
    subroutines and turn them into something less tightly bound.  */
 
 void
-lower_nested_functions (tree fndecl)
+/* APPLE LOCAL radar 6305545 */
+lower_nested_functions (tree fndecl, bool skip_outermost_fndecl)
 {
   struct cgraph_node *cgn;
 
@@ -2236,6 +2237,13 @@
 #endif
   /* LLVM LOCAL end */
   root = create_nesting_tree (cgn);
+  /* APPLE LOCAL begin radar 6305545 */
+  /* If skip_outermost_fndecl is true, we are lowering nested functions of
+     a constructor/destructor which are cloned and thrown away. But we
+     still have to lower their nested functions, but not the outermost function. */
+  if (skip_outermost_fndecl)
+    root = root->inner;
+  /* APPLE LOCAL end radar 6305545 */
   walk_all_functions (convert_nonlocal_reference, root);
   walk_all_functions (convert_local_reference, root);
   walk_all_functions (convert_nl_goto_reference, root);





More information about the llvm-commits mailing list