This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH 08/11] Example of converting global state to per-pass state
- From: David Malcolm <dmalcolm at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: David Malcolm <dmalcolm at redhat dot com>
- Date: Fri, 26 Jul 2013 11:04:38 -0400
- Subject: [PATCH 08/11] Example of converting global state to per-pass state
- References: <1374851081-32153-1-git-send-email-dmalcolm at redhat dot com>
gcc/testsuite/
Example of converting global state to per-pass state.
* gcc.dg/plugin/one_time_plugin.c (one_pass::execute): Convert
global state "static int counter" to...
(one_pass::counter): ...this instance data.
---
gcc/testsuite/gcc.dg/plugin/one_time_plugin.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/gcc/testsuite/gcc.dg/plugin/one_time_plugin.c b/gcc/testsuite/gcc.dg/plugin/one_time_plugin.c
index 7e93e65..c4dace5 100644
--- a/gcc/testsuite/gcc.dg/plugin/one_time_plugin.c
+++ b/gcc/testsuite/gcc.dg/plugin/one_time_plugin.c
@@ -33,13 +33,16 @@ class one_pass : public gimple_opt_pass
{
public:
one_pass(gcc::context *ctxt)
- : gimple_opt_pass(pass_data_one_pass, ctxt)
+ : gimple_opt_pass(pass_data_one_pass, ctxt),
+ counter(0)
{}
/* opt_pass methods: */
bool gate ();
unsigned int execute ();
+private:
+ int counter;
}; // class one_pass
} // anon namespace
@@ -51,8 +54,6 @@ bool one_pass::gate (void)
unsigned int one_pass::execute ()
{
- static int counter = 0;
-
if (counter > 0) {
printf ("Executed more than once \n");
}
--
1.7.11.7