public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Patch: make cfun a non-lvalue
@ 2007-11-07 20:11 Tom Tromey
  2007-11-15 20:29 ` Diego Novillo
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2007-11-07 20:11 UTC (permalink / raw)
  To: Gcc Patch List

I noticed recently that a couple places still set cfun directly --
contrary to how the variable is documented.

This patch changes cfun so that it is not an lvalue.  This is done by
macro hackery.  The only odd bit in this patch is the need to #undef
cfun in gtype-desc.c.  I considered adding a new GTY tag to tell
gengtype about this, but that seemed like overkill for a single use,
so I simply added a hack directly to gengtype.c.

Bootstrapped and regtested on x86 FC-6.  Ok?

Tom

:ADDPATCH middle-end:

ChangeLog:
2007-11-07  Tom Tromey  <tromey@redhat.com>

	* tree-parloops.c (create_loop_fn): Use set_cfun.
	* gengtype.c (open_base_files): Emit #undef cfun.
	* ipa-struct-reorg.c (do_reorg_1): Use set_cfun.
	* function.h (cfun): New define.
	* function.c: Undefine cfun.

Index: tree-parloops.c
===================================================================
--- tree-parloops.c	(revision 129934)
+++ tree-parloops.c	(working copy)
@@ -1,5 +1,5 @@
 /* Loop autoparallelization.
-   Copyright (C) 2006 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2007 Free Software Foundation, Inc.
    Contributed by Sebastian Pop <pop@cri.ensmp.fr> and
    Zdenek Dvorak <dvorakz@suse.cz>.
 
@@ -1252,7 +1252,7 @@
 
   /* The call to allocate_struct_function clobbers CFUN, so we need to restore
      it.  */
-  cfun = act_cfun;
+  set_cfun (act_cfun);
 
   return decl;
 }
Index: gengtype.c
===================================================================
--- gengtype.c	(revision 129934)
+++ gengtype.c	(working copy)
@@ -1543,6 +1543,10 @@
     gtype_desc_c = create_file ("GCC", "gtype-desc.c");
     for (ifp = ifiles; *ifp; ifp++)
       oprintf (gtype_desc_c, "#include \"%s\"\n", *ifp);
+
+    /* Make sure we handle "cfun" specially.  */
+    oprintf (gtype_desc_c, "\n/* See definition in function.h.  */\n");
+    oprintf (gtype_desc_c, "#undef cfun\n");
   }
 }
 
Index: ipa-struct-reorg.c
===================================================================
--- ipa-struct-reorg.c	(revision 129934)
+++ ipa-struct-reorg.c	(working copy)
@@ -3628,7 +3628,7 @@
 	pop_cfun ();
       }
 
-  cfun = NULL;
+  set_cfun (NULL);
 }
 
 /* This function creates new global struct variables.
Index: function.c
===================================================================
--- function.c	(revision 129936)
+++ function.c	(working copy)
@@ -66,6 +66,9 @@
 #include "timevar.h"
 #include "vecprim.h"
 
+/* So we can assign to cfun in this file.  */
+#undef cfun
+
 #ifndef LOCAL_ALIGNMENT
 #define LOCAL_ALIGNMENT(TYPE, ALIGNMENT) ALIGNMENT
 #endif
Index: function.h
===================================================================
--- function.h	(revision 129934)
+++ function.h	(working copy)
@@ -466,6 +466,11 @@
 /* The function currently being compiled.  */
 extern GTY(()) struct function *cfun;
 
+/* In order to ensure that cfun is not set directly, we redefine it so
+   that it is not an lvalue.  Rather than assign to cfun, use
+   push_cfun or set_cfun.  */
+#define cfun (cfun + 0)
+
 /* Pointer to chain of `struct function' for containing functions.  */
 extern GTY(()) struct function *outer_function_chain;
 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Patch: make cfun a non-lvalue
  2007-11-07 20:11 Patch: make cfun a non-lvalue Tom Tromey
@ 2007-11-15 20:29 ` Diego Novillo
  2007-11-15 21:13   ` Tom Tromey
  0 siblings, 1 reply; 7+ messages in thread
From: Diego Novillo @ 2007-11-15 20:29 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Gcc Patch List

Tom Tromey wrote:

> 	* tree-parloops.c (create_loop_fn): Use set_cfun.
> 	* gengtype.c (open_base_files): Emit #undef cfun.
> 	* ipa-struct-reorg.c (do_reorg_1): Use set_cfun.
> 	* function.h (cfun): New define.
> 	* function.c: Undefine cfun.

There are other places that set 'cfun', though.  IIRC, tree-inline.c and 
omp-low.c do.

Patch is OK otherwise.


Diego.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Patch: make cfun a non-lvalue
  2007-11-15 20:29 ` Diego Novillo
@ 2007-11-15 21:13   ` Tom Tromey
  2007-11-15 21:58     ` Diego Novillo
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2007-11-15 21:13 UTC (permalink / raw)
  To: Diego Novillo; +Cc: Gcc Patch List

>>>>> "Diego" == Diego Novillo <dnovillo@google.com> writes:

Diego> Tom Tromey wrote:
>> * tree-parloops.c (create_loop_fn): Use set_cfun.
>> * gengtype.c (open_base_files): Emit #undef cfun.
>> * ipa-struct-reorg.c (do_reorg_1): Use set_cfun.
>> * function.h (cfun): New define.
>> * function.c: Undefine cfun.

Diego> There are other places that set 'cfun', though.  IIRC, tree-inline.c
Diego> and omp-low.c do.

I don't see those in my tree.  Maybe those assignments were removed at
some point?  Also, this patch has survived multiple bootstraps, which
would have caught any assignments -- that's how I found the ones I
fixed.

Diego> Patch is OK otherwise.

I'll check it in shortly, thanks.

Tom

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Patch: make cfun a non-lvalue
  2007-11-15 21:13   ` Tom Tromey
@ 2007-11-15 21:58     ` Diego Novillo
  2007-11-15 23:01       ` Tom Tromey
  0 siblings, 1 reply; 7+ messages in thread
From: Diego Novillo @ 2007-11-15 21:58 UTC (permalink / raw)
  To: tromey; +Cc: Gcc Patch List

Tom Tromey wrote:

> I don't see those in my tree.  Maybe those assignments were removed at
> some point?  Also, this patch has survived multiple bootstraps, which
> would have caught any assignments -- that's how I found the ones I
> fixed.

Yeah, if there are no others then I was probably misremembering or 
they've been fixed.


Thanks.  Diego.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Patch: make cfun a non-lvalue
  2007-11-15 21:58     ` Diego Novillo
@ 2007-11-15 23:01       ` Tom Tromey
  2007-11-24 10:14         ` Mark Mitchell
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2007-11-15 23:01 UTC (permalink / raw)
  To: Diego Novillo; +Cc: Gcc Patch List

>>>>> "Diego" == Diego Novillo <dnovillo@google.com> writes:

Diego> Yeah, if there are no others then I was probably misremembering
Diego> or they've been fixed.

When I went to commit this I realized I omitted part of the patch.

Because 'cfun' is now a macro, using it as an identifier elsewhere can
cause compile failures.

Here's the additional bits that I neglected to send earlier.  This was
part of the original patch, and boostrapped and regtested multiple
times along with the rest of it.

Ok?

Tom

2007-11-15  Tom Tromey  <tromey@redhat.com>

	* tree-ssa-structalias.c (ipa_pta_execute): Rename 'cfun' to
	'func'.

Index: tree-ssa-structalias.c
===================================================================
--- tree-ssa-structalias.c	(revision 130208)
+++ tree-ssa-structalias.c	(working copy)
@@ -5561,17 +5561,17 @@
     {
       if (node->analyzed && cgraph_is_master_clone (node))
 	{
-	  struct function *cfun = DECL_STRUCT_FUNCTION (node->decl);
+	  struct function *func = DECL_STRUCT_FUNCTION (node->decl);
 	  basic_block bb;
 	  tree old_func_decl = current_function_decl;
 	  if (dump_file)
 	    fprintf (dump_file,
 		     "Generating constraints for %s\n",
 		     cgraph_node_name (node));
-	  push_cfun (cfun);
+	  push_cfun (func);
 	  current_function_decl = node->decl;
 
-	  FOR_EACH_BB_FN (bb, cfun)
+	  FOR_EACH_BB_FN (bb, func)
 	    {
 	      block_stmt_iterator bsi;
 	      tree phi;

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Patch: make cfun a non-lvalue
  2007-11-15 23:01       ` Tom Tromey
@ 2007-11-24 10:14         ` Mark Mitchell
  2007-11-25 23:57           ` Tom Tromey
  0 siblings, 1 reply; 7+ messages in thread
From: Mark Mitchell @ 2007-11-24 10:14 UTC (permalink / raw)
  To: tromey; +Cc: Diego Novillo, Gcc Patch List

Tom Tromey wrote:

> 2007-11-15  Tom Tromey  <tromey@redhat.com>
> 
> 	* tree-ssa-structalias.c (ipa_pta_execute): Rename 'cfun' to
> 	'func'.

OK.

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Patch: make cfun a non-lvalue
  2007-11-24 10:14         ` Mark Mitchell
@ 2007-11-25 23:57           ` Tom Tromey
  0 siblings, 0 replies; 7+ messages in thread
From: Tom Tromey @ 2007-11-25 23:57 UTC (permalink / raw)
  To: Mark Mitchell; +Cc: Diego Novillo, Gcc Patch List

>>>>> "Mark" == Mark Mitchell <mark@codesourcery.com> writes:

Mark> Tom Tromey wrote:
>> 2007-11-15  Tom Tromey  <tromey@redhat.com>
>> 
>> * tree-ssa-structalias.c (ipa_pta_execute): Rename 'cfun' to
>> 'func'.

Mark> OK.

Thanks Mark.  I should have mentioned, though, that Diego approved
this on irc and I've already checked it in.

Tom

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-11-25 16:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-07 20:11 Patch: make cfun a non-lvalue Tom Tromey
2007-11-15 20:29 ` Diego Novillo
2007-11-15 21:13   ` Tom Tromey
2007-11-15 21:58     ` Diego Novillo
2007-11-15 23:01       ` Tom Tromey
2007-11-24 10:14         ` Mark Mitchell
2007-11-25 23:57           ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).