This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] DECL_NO_STATIC_CHAIN -> DECL_STATIC_CHAIN


On Wed, Sep 23, 2009 at 12:11:18PM -0700, Richard Henderson wrote:
>> @@ -1323,6 +1323,7 @@ c_parser_declaration_or_fndef (c_parser
>>        if (nested)
>>  	{
>>  	  tree decl = current_function_decl;
>> +	  DECL_STATIC_CHAIN (decl) = 1;
>
> I think a comment is definitely required here, noting that this will be  
> reset by tree-nested.c if the chain isn't needed.

Added.

> Don't you need something similar for the Ada frontend?  Someone ought to  
> be able to create an Ada testcase similar to nested-fn-2.c...

And this as well.

Here is what I've committed:

2009-09-24  Jakub Jelinek  <jakub@redhat.com>

	* cgraphunit.c (cgraph_lower_function): Revert last change.
	* targhooks.c (default_static_chain): Use !DECL_STATIC_CHAIN
	instead of DECL_NO_STATIC_CHAIN.
	* tree-cfg.c (verify_gimple_call): Likewise.
	* tree-nested.c (get_chain_decl, get_chain_field,
	convert_tramp_reference_op, convert_gimple_call): Likewise.
	(convert_all_function_calls): Likewise.  Always set or clear
	DECL_STATIC_CHAIN initially, for !n->outer clear it.
	(lower_nested_functions): Remove DECL_NO_STATIC_CHAIN checking code.
	* c-parser.c (c_parser_declaration_or_fndef): Set DECL_STATIC_CHAIN
	if nested.
	* print-tree.c (print_node): Handle DECL_STATIC_CHAIN instead of
	DECL_NO_STATIC_CHAIN.
	* config/i386/i386.c (ix86_static_chain): Use !DECL_STATIC_CHAIN
	instead of DECL_NO_STATIC_CHAIN.
	(ix86_function_regparm, find_drap_reg): Likewise.  Don't test
	decl_function_context.
	* varasm.c (initializer_constant_valid_p): Likewise.
	* tree.h (DECL_NO_STATIC_CHAIN): Renamed to ...
	(DECL_STATIC_CHAIN): ... this.
	* config/moxie/moxie.c (moxie_static_chain): Use !DECL_STATIC_CHAIN
	instead of DECL_NO_STATIC_CHAIN.

	* method.c (make_thunk, make_alias_for): Don't set
	DECL_NO_STATIC_CHAIN.
	* decl.c (builtin_function_1, grokfndecl): Likewise.
	* lex.c (build_lang_decl): Likewise.

	* gcc-interface/utils.c (gnat_pushdecl): Don't set
	DECL_NO_STATIC_CHAIN, set DECL_STATIC_CHAIN for
	nested functions.

	* testsuite/gcc.target/i386/pr12329.c: Adjust.

--- gcc/cgraphunit.c.jj	2009-09-23 20:03:39.000000000 +0200
+++ gcc/cgraphunit.c	2009-09-24 10:49:00.000000000 +0200
@@ -498,11 +498,6 @@ cgraph_lower_function (struct cgraph_nod
     lower_nested_functions (node->decl);
   gcc_assert (!node->nested);
 
-  /* Non-nested functions never need a static chain.  */
-  if (!DECL_NO_STATIC_CHAIN (node->decl)
-      && decl_function_context (node->decl) == NULL)
-    DECL_NO_STATIC_CHAIN (node->decl) = 1;
-
   tree_lowering_passes (node->decl);
   node->lowered = true;
 }
--- gcc/targhooks.c.jj	2009-09-24 10:44:09.000000000 +0200
+++ gcc/targhooks.c	2009-09-24 10:49:00.000000000 +0200
@@ -631,7 +631,7 @@ default_internal_arg_pointer (void)
 rtx
 default_static_chain (const_tree fndecl, bool incoming_p)
 {
-  if (DECL_NO_STATIC_CHAIN (fndecl))
+  if (!DECL_STATIC_CHAIN (fndecl))
     return NULL;
 
   if (incoming_p)
--- gcc/cp/method.c.jj	2009-09-23 20:03:39.000000000 +0200
+++ gcc/cp/method.c	2009-09-24 10:49:00.000000000 +0200
@@ -151,9 +151,6 @@ make_thunk (tree function, bool this_adj
   DECL_CONSTRUCTOR_P (thunk) = 0;
   DECL_EXTERNAL (thunk) = 1;
   DECL_ARTIFICIAL (thunk) = 1;
-  /* Even if this thunk is a member of a local class, we don't
-     need a static chain.  */
-  DECL_NO_STATIC_CHAIN (thunk) = 1;
   /* The THUNK is not a pending inline, even if the FUNCTION is.  */
   DECL_PENDING_INLINE_P (thunk) = 0;
   DECL_DECLARED_INLINE_P (thunk) = 0;
@@ -281,7 +278,6 @@ make_alias_for (tree function, tree newi
   DECL_CONSTRUCTOR_P (alias) = 0;
   DECL_EXTERNAL (alias) = 0;
   DECL_ARTIFICIAL (alias) = 1;
-  DECL_NO_STATIC_CHAIN (alias) = 1;
   DECL_PENDING_INLINE_P (alias) = 0;
   DECL_DECLARED_INLINE_P (alias) = 0;
   DECL_USE_TEMPLATE (alias) = 0;
--- gcc/cp/decl.c.jj	2009-09-23 20:03:41.000000000 +0200
+++ gcc/cp/decl.c	2009-09-24 10:49:00.000000000 +0200
@@ -3580,10 +3580,6 @@ builtin_function_1 (tree decl, tree cont
 
   retrofit_lang_decl (decl);
 
-  /* All nesting of C++ functions is lexical; there is never a "static
-     chain" in the sense of GNU C nested functions.  */
-  DECL_NO_STATIC_CHAIN (decl) = 1;
-
   DECL_ARTIFICIAL (decl) = 1;
   SET_OVERLOADED_OPERATOR_CODE (decl, ERROR_MARK);
   SET_DECL_LANGUAGE (decl, lang_c);
@@ -6779,9 +6775,6 @@ grokfndecl (tree ctype,
       && !grok_op_properties (decl, /*complain=*/true))
     return NULL_TREE;
 
-  if (ctype && decl_function_context (decl))
-    DECL_NO_STATIC_CHAIN (decl) = 1;
-
   if (funcdef_flag)
     /* Make the init_value nonzero so pushdecl knows this is not
        tentative.  error_mark_node is replaced later with the BLOCK.  */
--- gcc/cp/lex.c.jj	2009-09-23 20:03:39.000000000 +0200
+++ gcc/cp/lex.c	2009-09-24 10:49:00.000000000 +0200
@@ -516,11 +516,6 @@ build_lang_decl (enum tree_code code, tr
 		  code, name, type);
   retrofit_lang_decl (t);
 
-  /* All nesting of C++ functions is lexical; there is never a "static
-     chain" in the sense of GNU C nested functions.  */
-  if (code == FUNCTION_DECL)
-    DECL_NO_STATIC_CHAIN (t) = 1;
-
   return t;
 }
 
--- gcc/tree-cfg.c.jj	2009-09-23 20:03:39.000000000 +0200
+++ gcc/tree-cfg.c	2009-09-24 10:49:00.000000000 +0200
@@ -3575,7 +3575,7 @@ verify_gimple_call (gimple stmt)
     }
 
   /* If there is a static chain argument, this should not be an indirect
-     call, and the decl should not have DECL_NO_STATIC_CHAIN set.  */
+     call, and the decl should have DECL_STATIC_CHAIN set.  */
   if (gimple_call_chain (stmt))
     {
       if (TREE_CODE (fn) != ADDR_EXPR
@@ -3586,7 +3586,7 @@ verify_gimple_call (gimple stmt)
 	}
       fn = TREE_OPERAND (fn, 0);
 
-      if (DECL_NO_STATIC_CHAIN (fn))
+      if (!DECL_STATIC_CHAIN (fn))
 	{
 	  error ("static chain with function that doesn't use one");
 	  return true;
--- gcc/c-parser.c.jj	2009-09-23 20:03:39.000000000 +0200
+++ gcc/c-parser.c	2009-09-24 11:05:07.000000000 +0200
@@ -1323,6 +1323,11 @@ c_parser_declaration_or_fndef (c_parser 
       if (nested)
 	{
 	  tree decl = current_function_decl;
+	  /* Mark nested functions as needing static-chain initially.
+	     lower_nested_functions will recompute it but the
+	     DECL_STATIC_CHAIN flag is also used before that happens,
+	     by initializer_constant_valid_p.  See gcc.dg/nested-fn-2.c.  */
+	  DECL_STATIC_CHAIN (decl) = 1;
 	  add_stmt (fnbody);
 	  finish_function ();
 	  c_pop_function_context ();
--- gcc/tree-nested.c.jj	2009-09-23 20:03:39.000000000 +0200
+++ gcc/tree-nested.c	2009-09-24 10:49:54.000000000 +0200
@@ -353,11 +353,11 @@ get_chain_decl (struct nesting_info *inf
 
       if (dump_file
           && (dump_flags & TDF_DETAILS)
-	  && DECL_NO_STATIC_CHAIN (info->context))
-	fprintf (dump_file, "Resetting no-static-chain for %s\n",
+	  && !DECL_STATIC_CHAIN (info->context))
+	fprintf (dump_file, "Setting static-chain for %s\n",
 		 lang_hooks.decl_printable_name (info->context, 2));
 
-      DECL_NO_STATIC_CHAIN (info->context) = 0;
+      DECL_STATIC_CHAIN (info->context) = 1;
     }
   return decl;
 }
@@ -387,11 +387,11 @@ get_chain_field (struct nesting_info *in
 
       if (dump_file
           && (dump_flags & TDF_DETAILS)
-	  && DECL_NO_STATIC_CHAIN (info->context))
-	fprintf (dump_file, "Resetting no-static-chain for %s\n",
+	  && !DECL_STATIC_CHAIN (info->context))
+	fprintf (dump_file, "Setting static-chain for %s\n",
 		 lang_hooks.decl_printable_name (info->context, 2));
 
-      DECL_NO_STATIC_CHAIN (info->context) = 0;
+      DECL_STATIC_CHAIN (info->context) = 1;
     }
   return field;
 }
@@ -1872,7 +1872,7 @@ convert_tramp_reference_op (tree *tp, in
 
       /* If the nested function doesn't use a static chain, then
 	 it doesn't need a trampoline.  */
-      if (DECL_NO_STATIC_CHAIN (decl))
+      if (!DECL_STATIC_CHAIN (decl))
 	break;
 
       /* If we don't want a trampoline, then don't build one.  */
@@ -1972,7 +1972,7 @@ convert_gimple_call (gimple_stmt_iterato
       if (!decl)
 	break;
       target_context = decl_function_context (decl);
-      if (target_context && !DECL_NO_STATIC_CHAIN (decl))
+      if (target_context && DECL_STATIC_CHAIN (decl))
 	{
 	  gimple_call_set_chain (stmt, get_static_chain (info, target_context,
 							 &wi->gsi));
@@ -2046,20 +2046,20 @@ convert_all_function_calls (struct nesti
   int iter_count;
   bool any_changed;
 
-  /* First, optimistically set no_static_chain for all decls that haven't
+  /* First, optimistically clear static_chain for all decls that haven't
      used the static chain already for variable access.  */
   FOR_EACH_NEST_INFO (n, root)
     {
       tree decl = n->context;
-      if (n->outer && !n->chain_decl && !n->chain_field)
+      if (!n->outer || (!n->chain_decl && !n->chain_field))
 	{
-	  DECL_NO_STATIC_CHAIN (decl) = 1;
+	  DECL_STATIC_CHAIN (decl) = 0;
 	  if (dump_file && (dump_flags & TDF_DETAILS))
-	    fprintf (dump_file, "Guessing no-static-chain for %s\n",
+	    fprintf (dump_file, "Guessing no static-chain for %s\n",
 		     lang_hooks.decl_printable_name (decl, 2));
 	}
       else
-	gcc_assert (!DECL_NO_STATIC_CHAIN (decl));
+	DECL_STATIC_CHAIN (decl) = 1;
     }
 
   /* Walk the functions and perform transformations.  Note that these
@@ -2081,7 +2081,7 @@ convert_all_function_calls (struct nesti
       FOR_EACH_NEST_INFO (n, root)
 	{
 	  tree decl = n->context;
-	  bool old_no_static_chain = DECL_NO_STATIC_CHAIN (decl);
+	  bool old_static_chain = DECL_STATIC_CHAIN (decl);
 
 	  walk_function (convert_tramp_reference_stmt,
 			 convert_tramp_reference_op, n);
@@ -2089,7 +2089,7 @@ convert_all_function_calls (struct nesti
 
 	  /* If a call to another function created the use of a chain
 	     within this function, we'll have to continue iteration.  */
-	  if (old_no_static_chain && !DECL_NO_STATIC_CHAIN (decl))
+	  if (!old_static_chain && DECL_STATIC_CHAIN (decl))
 	    any_changed = true;
 	}
     }
@@ -2337,7 +2337,7 @@ finalize_nesting_tree_1 (struct nesting_
 	  if (!field)
 	    continue;
 
-	  gcc_assert (!DECL_NO_STATIC_CHAIN (i->context));
+	  gcc_assert (DECL_STATIC_CHAIN (i->context));
 	  arg3 = build_addr (root->frame_decl, context);
 
 	  arg2 = build_addr (i->context, context);
@@ -2528,10 +2528,6 @@ lower_nested_functions (tree fndecl)
 {
   struct cgraph_node *cgn;
   struct nesting_info *root;
-#ifdef ENABLE_CHECKING
-  struct nesting_info *n;
-  bitmap orig_decl_no_static_chain;
-#endif
 
   /* If there are no nested functions, there's nothing to do.  */
   cgn = cgraph_node (fndecl);
@@ -2548,15 +2544,6 @@ lower_nested_functions (tree fndecl)
   bitmap_obstack_initialize (&nesting_info_bitmap_obstack);
   root = create_nesting_tree (cgn);
 
-#ifdef ENABLE_CHECKING
-  /* The C++ and Ada front ends set DECL_NO_STATIC_CHAIN in various
-     instances where they expect no static chain needed.  */
-  orig_decl_no_static_chain = BITMAP_ALLOC (&nesting_info_bitmap_obstack);
-  FOR_EACH_NEST_INFO (n, root)
-    if (DECL_NO_STATIC_CHAIN (n->context))
-      bitmap_set_bit (orig_decl_no_static_chain, DECL_UID (n->context));
-#endif
-
   walk_all_functions (convert_nonlocal_reference_stmt,
                       convert_nonlocal_reference_op,
 		      root);
@@ -2570,13 +2557,6 @@ lower_nested_functions (tree fndecl)
   finalize_nesting_tree (root);
   unnest_nesting_tree (root);
 
-#ifdef ENABLE_CHECKING
-  /* Validate the original settings of DECL_NO_STATIC_CHAIN.  */
-  FOR_EACH_NEST_INFO (n, root)
-    if (bitmap_bit_p (orig_decl_no_static_chain, DECL_UID (n->context)))
-      gcc_assert (DECL_NO_STATIC_CHAIN (n->context));
-#endif
-
   free_nesting_tree (root);
   bitmap_obstack_release (&nesting_info_bitmap_obstack);
 
--- gcc/print-tree.c.jj	2009-09-23 20:03:39.000000000 +0200
+++ gcc/print-tree.c	2009-09-24 10:49:00.000000000 +0200
@@ -381,8 +381,8 @@ print_node (FILE *file, const char *pref
 	fputs (" autoinline", file);
       if (code == FUNCTION_DECL && DECL_BUILT_IN (node))
 	fputs (" built-in", file);
-      if (code == FUNCTION_DECL && DECL_NO_STATIC_CHAIN (node))
-	fputs (" no-static-chain", file);
+      if (code == FUNCTION_DECL && DECL_STATIC_CHAIN (node))
+	fputs (" static-chain", file);
 
       if (code == FIELD_DECL && DECL_PACKED (node))
 	fputs (" packed", file);
--- gcc/config/moxie/moxie.c.jj	2009-09-23 20:03:39.000000000 +0200
+++ gcc/config/moxie/moxie.c	2009-09-24 10:49:00.000000000 +0200
@@ -460,7 +460,7 @@ moxie_static_chain (const_tree fndecl, b
 {
   rtx addr, mem;
 
-  if (DECL_NO_STATIC_CHAIN (fndecl))
+  if (!DECL_STATIC_CHAIN (fndecl))
     return NULL;
 
   if (incoming_p)
--- gcc/config/i386/i386.c.jj	2009-09-23 20:03:39.000000000 +0200
+++ gcc/config/i386/i386.c	2009-09-24 10:49:00.000000000 +0200
@@ -4508,9 +4508,7 @@ ix86_function_regparm (const_tree type, 
 
 	  /* We don't want to use regparm(3) for nested functions as
 	     these use a static chain pointer in the third argument.  */
-	  if (local_regparm == 3
-	      && decl_function_context (decl)
-	      && !DECL_NO_STATIC_CHAIN (decl))
+	  if (local_regparm == 3 && DECL_STATIC_CHAIN (decl))
 	    local_regparm = 2;
 
 	  /* Each fixed register usage increases register pressure,
@@ -8128,9 +8126,7 @@ find_drap_reg (void)
 	 Since function with tail call may use any caller-saved
 	 registers in epilogue, DRAP must not use caller-saved
 	 register in such case.  */
-      if ((decl_function_context (decl)
-	   && !DECL_NO_STATIC_CHAIN (decl))
-	  || crtl->tail_call_emit)
+      if (DECL_STATIC_CHAIN (decl) || crtl->tail_call_emit)
 	return R13_REG;
 
       return R10_REG;
@@ -8141,9 +8137,7 @@ find_drap_reg (void)
 	 Since function with tail call may use any caller-saved
 	 registers in epilogue, DRAP must not use caller-saved
 	 register in such case.  */
-      if ((decl_function_context (decl)
-	   && !DECL_NO_STATIC_CHAIN (decl))
-	  || crtl->tail_call_emit)
+      if (DECL_STATIC_CHAIN (decl) || crtl->tail_call_emit)
 	return DI_REG;
     
       /* Reuse static chain register if it isn't used for parameter
@@ -19811,7 +19805,7 @@ ix86_static_chain (const_tree fndecl, bo
 {
   unsigned regno;
 
-  if (DECL_NO_STATIC_CHAIN (fndecl))
+  if (!DECL_STATIC_CHAIN (fndecl))
     return NULL;
 
   if (TARGET_64BIT)
--- gcc/ada/gcc-interface/utils.c.jj	2009-09-23 20:03:39.000000000 +0200
+++ gcc/ada/gcc-interface/utils.c	2009-09-24 11:07:29.000000000 +0200
@@ -439,9 +439,12 @@ gnat_pushdecl (tree decl, Node_Id gnat_n
     {
       DECL_CONTEXT (decl) = current_function_decl;
 
-      /* Functions imported in another function are not really nested.  */
-      if (TREE_CODE (decl) == FUNCTION_DECL && TREE_PUBLIC (decl))
-	DECL_NO_STATIC_CHAIN (decl) = 1;
+      /* Functions imported in another function are not really nested.
+	 For really nested functions mark them initially as needing
+	 a static chain for uses of that flag before unnesting;
+	 lower_nested_functions will then recompute it.  */
+      if (TREE_CODE (decl) == FUNCTION_DECL && !TREE_PUBLIC (decl))
+	DECL_STATIC_CHAIN (decl) = 1;
     }
 
   TREE_NO_WARNING (decl) = (gnat_node == Empty || Warnings_Off (gnat_node));
--- gcc/varasm.c.jj	2009-09-23 20:03:39.000000000 +0200
+++ gcc/varasm.c	2009-09-24 10:49:00.000000000 +0200
@@ -4212,8 +4212,7 @@ initializer_constant_valid_p (tree value
 	    /* Taking the address of a nested function involves a trampoline,
 	       unless we don't need or want one.  */
 	    if (TREE_CODE (op0) == FUNCTION_DECL
-		&& decl_function_context (op0)
-		&& !DECL_NO_STATIC_CHAIN (op0)
+		&& DECL_STATIC_CHAIN (op0)
 		&& !TREE_NO_TRAMPOLINE (value))
 	      return NULL_TREE;
 	    /* "&{...}" requires a temporary to hold the constructed
--- gcc/tree.h.jj	2009-09-23 20:03:39.000000000 +0200
+++ gcc/tree.h	2009-09-24 10:49:00.000000000 +0200
@@ -3141,9 +3141,8 @@ struct GTY(())
 #define DECL_NO_LIMIT_STACK(NODE) \
   (FUNCTION_DECL_CHECK (NODE)->function_decl.no_limit_stack)
 
-/* In a FUNCTION_DECL with a nonzero DECL_CONTEXT, indicates that a
-   static chain is not needed.  */
-#define DECL_NO_STATIC_CHAIN(NODE) \
+/* In a FUNCTION_DECL indicates that a static chain is needed.  */
+#define DECL_STATIC_CHAIN(NODE) \
   (FUNCTION_DECL_CHECK (NODE)->function_decl.regdecl_flag)
 
 /* Nonzero for a decl that cgraph has decided should be inlined into
--- gcc/testsuite/gcc.target/i386/pr12329.c.jj	2009-09-23 20:03:39.000000000 +0200
+++ gcc/testsuite/gcc.target/i386/pr12329.c	2009-09-24 10:49:00.000000000 +0200
@@ -6,7 +6,7 @@ extern void abort (void);
 
 int test_nested (int i)
 {
-  int __attribute__ ((__noinline__, __regparm__(3))) foo(int j, int k, int l) /* { dg-error "nested functions are limited to 2 register parameters" } */
+  int __attribute__ ((__noinline__, __regparm__(3))) foo(int j, int k, int l)
   {
     return i + j + k + l;
   }


	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]