Patch: make cfun a non-lvalue

Tom Tromey tromey@redhat.com
Wed Nov 7 20:11:00 GMT 2007


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;
 



More information about the Gcc-patches mailing list