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]

[patch][plugin] Fix bug in pass insertion


Hello All,
?The attached patch fixes a bug that could result in a plugin pass
being inserted multiple times, even though it
?was specified to inserted only once.? Also included is a testcase for this bug.
?This bug occurs when plugin pass A that is to be inserted after gcc
pass B have the same name.
This fix simply skips newly inserted passes while scanning through the
list of passes.
This patch was bootstrapped on? x86_64-unknown-linux-gnu
?make -k check shows no regression.

Thanks

tunji

2009-06-04? Olatunji Ruwase???? <tjruwase@google.com>
??????? * plugin.c(position_pass): Skip newly inserted pass during list
??????? traversal to avoid repeated insertion.

2009-06-04? Olatunji Ruwase?? <tjruwase@google.com>
??????? * gcc.dg/plugin/one_time_plugin.
c New test to detect multiple
??????? insertions of a plugin pass.
??????? * gcc.dg/plugin/one_time-test-1.c New test case
Index: gcc/testsuite/gcc.dg/plugin/plugin.exp
==============================
=====================================
--- gcc/testsuite/gcc.dg/plugin/plugin.exp????? (revision 148188)
+++ gcc/testsuite/gcc.dg/plugin/plugin.exp????? (working copy)
@@ -49,6 +49,7 @@ load_lib plugin-support.exp
?set plugin_test_list [list \
???? { selfassign.c self-assign-test-1.c self-assign-test-2.c } \
???? { ggcplug.c ggcplug-test-1.c } \
+??? { one_time_plugin.c one_time-test-1.c } \
?]

?foreach plugin_test $plugin_test_list {
Index: gcc/testsuite/gcc.dg/plugin/one_time-test-1.c
===================================================================
--- gcc/testsuite/gcc.dg/plugin/one_time-test-1.c?????? (revision 0)
+++ gcc/testsuite/gcc.dg/plugin/one_time-test-1.c?????? (revision 0)
@@ -0,0 +1,8 @@
+/* Test that pass is inserted and invoked once. */
+/* { dg-do compile } */
+/* { dg-options "-O" } */
+
+int main (int argc, char **argv)
+{
+? return 0;
+}
Index: gcc/testsuite/gcc.dg/plugin/one_time_plugin.c
===================================================================
--- gcc/testsuite/gcc.dg/plugin/one_time_plugin.c?????? (revision 0)
+++ gcc/testsuite/gcc.dg/plugin/one_time_plugin.c?????? (revision 0)
@@ -0,0 +1,60 @@
+/* Plugin that prints message if it inserted (and invoked) more than once. */
+#include "config.h"
+#include "gcc-plugin.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "toplev.h"
+#include "gimple.h"
+#include "tree-pass.h"
+#include "intl.h"
+
+static bool one_pass_gate (void)
+{
+? return true;
+}
+
+static unsigned int one_pass_exec (void)
+{
+? static int counter = 0;
+
+? if (counter > 0) {
+??? printf ("Executed more than once \n");
+ }
+ counter++;
+}
+
+struct gimple_opt_pass one_pass =
+{
+? {
+? GIMPLE_PASS,
+? "useless",?????????????????????????? /* name */
+? one_pass_gate,???????????????????????? /* gate */
+? one_pass_exec,?????? /* execute */
+? NULL,???????????????????????????????? /* sub */
+? NULL,???????????????????????????????? /* next */
+? 0,??????????????????????????????????? /* static_pass_number */
+? 0,??????????????????????????????????? /* tv_id */
+? PROP_gimple_any,????????????????????? /* properties_required */
+? 0,??????????????????????????????????? /* properties_provided */
+? 0,??????????????????????????????????? /* properties_destroyed */
+? 0,??????????????????????????????????? /* todo_flags_start */
+? TODO_dump_func??????????????????????? /* todo_flags_finish */
+? }
+};
+
+
+int plugin_init (struct plugin_name_args *plugin_info,
+???????????????? struct plugin_gcc_version *version)
+{
+? struct plugin_pass p;
+
+? p.pass = &one_pass.pass;
+? p.reference_pass_name = "useless";
+? p.ref_pass_instance_number = 1;
+? p.pos_op = PASS_POS_INSERT_AFTER;
+
+? register_callback ("one_pass", PLUGIN_PASS_MANAGER_SETUP, NULL, &p);
+
+? return 0;
+}

Index: gcc/plugin.c
===================================================================
--- gcc/plugin.c??? (revision 148188)
+++ gcc/plugin.c??? (working copy)
@@ -336,6 +336,8 @@ position_pass (struct plugin_pass *plugi
?????????????? case PASS_POS_INSERT_AFTER:
???????????????? new_pass->next = pass->next;
???????????????? pass->next = new_pass;
+??? ??? /* Skip newly inserted pass to avoid repeated insertions. */
+??? ??? pass = new_pass;
???????????????? break;
?????????????? case PASS_POS_INSERT_BEFORE:
???????????????? new_pass->next = pass;

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