Assign join points also do not instrument advice calls.
authorJustin Seyster <jseyster@cs.sunysb.edu>
Wed, 8 Sep 2010 02:49:49 +0000 (22:49 -0400)
committerJustin Seyster <jseyster@cs.sunysb.edu>
Wed, 8 Sep 2010 02:49:49 +0000 (22:49 -0400)
The only time an advice call would appear in an assignment is when
it's a distributor function.  A modification to
duplicate_function_body() was also necessary so that the inserted
distributor call is in the advice table.

src/aop-duplicate.c
src/aop-pc-assign.c
test/plugin-reinst-dup.c [new file with mode: 0644]
test/reinst-dup-hooks.c [new file with mode: 0644]
test/reinst-dup-target.c [new file with mode: 0644]
test/reinst.xml

index 3cc03e56ed6b84e0eca6868d03c7e517533c3cc0..57bab19afdd8708daeaefabea1c2a6c47e65309f 100644 (file)
@@ -297,17 +297,15 @@ duplicate_function_body (const char *tmpvar_name, gimple call)
       else
        {
          /* insert: tmpvar = distributor_fn(...) */
-         /* TODO: No need to copy. */
-         gimple distributor_fn = gimple_copy(call);
-         aop_assert (gimple_code (distributor_fn) == GIMPLE_CALL);
+         aop_assert (gimple_code (call) == GIMPLE_CALL);
 
          /* TODO: Do we need this? */
          if (gimple_in_ssa_p (cfun))
            {
-             tmpvar = make_ssa_name (tmpvar, distributor_fn);
+             tmpvar = make_ssa_name (tmpvar, call);
            }
-         gimple_call_set_lhs (distributor_fn, tmpvar);
-         gsi_insert_before (&gsi, distributor_fn, GSI_SAME_STMT);
+         gimple_call_set_lhs (call, tmpvar);
+         gsi_insert_before (&gsi, call, GSI_SAME_STMT);
        }       
 
       /* insert: if (tmpvar) goto <new_label> else goto <old_label> */
index 99673a682d557d40e9f8107479bed73796df5a23..cb5b7e6cb3166f66e1a1942cf13e5bd94d3d690b 100644 (file)
@@ -38,6 +38,7 @@
 #include "aop-dynval.h"
 #include "aop-pointcut.h"
 #include "aop-type.h"
+#include "aop-weave.h"
 
 /**
  * \defgroup assign_pc Assignment Pointcut Functions
@@ -290,6 +291,11 @@ stmt_matches_pointcut (struct aop_pointcut *pc, gimple stmt)
       tree lhs = gimple_get_lhs(stmt);
       tree type = TREE_TYPE (gimple_get_lhs (stmt));
 
+      /* We never want to match a call that is actually one we
+        inserted! */
+      if (is_stmt_advice (stmt))
+       return false;
+
       /* Temp variables with matching type only match the pointcut if
         include_temp_vars is true. */
       return does_type_match (type, pc->pc_assign.type)
diff --git a/test/plugin-reinst-dup.c b/test/plugin-reinst-dup.c
new file mode 100644 (file)
index 0000000..63ac3b0
--- /dev/null
@@ -0,0 +1,50 @@
+#include <aop.h>
+#include <stdio.h>
+#include <string.h>
+
+AOP_I_AM_GPL_COMPATIBLE();
+
+int duplicated = 0;
+
+static void plugin_join_on_entry(struct aop_joinpoint *jp, void *data)
+{
+  const char *name;
+
+  name = aop_capture_function_name(jp);
+  if (name != NULL && strcmp(name, "foo") == 0) {
+    aop_duplicate(jp, "_distrib", AOP_TERM_ARG);
+    duplicated = 1;
+  }
+  else {
+    duplicated = 0;
+  }
+}
+
+static void plugin_join_on_assign(struct aop_joinpoint *jp, void *data)
+{
+  aop_insert_advice(jp, "_assign_advice", AOP_INSERT_BEFORE, AOP_TERM_ARG);
+}
+
+static unsigned int plugin_reinst_dup()
+{
+  struct aop_pointcut *pc;
+
+  pc = aop_match_function_entry();
+  aop_join_on(pc, plugin_join_on_entry, NULL);
+
+  if (duplicated) {
+    /* Duplication creates an assignment that we might accidentally
+       match during a join.  (This test is primarily to make sure that
+       doesn't happen! */
+    pc = aop_match_assignment_by_type(aop_t_all_signed());
+    aop_filter_include_temps (pc);
+    aop_join_on(pc, plugin_join_on_assign, NULL);
+  }
+
+  return 0;
+}
+
+AOP_MAIN_PROTO aop_main()
+{
+  aop_register_pass("reinst-dup", plugin_reinst_dup);
+}
diff --git a/test/reinst-dup-hooks.c b/test/reinst-dup-hooks.c
new file mode 100644 (file)
index 0000000..1d422d6
--- /dev/null
@@ -0,0 +1,11 @@
+#include <stdio.h>
+
+void _distrib()
+{
+  printf("In distributor.\n");
+}
+
+void _assign_advice()
+{
+  printf("In assign advice.\n");
+}
diff --git a/test/reinst-dup-target.c b/test/reinst-dup-target.c
new file mode 100644 (file)
index 0000000..4b413f0
--- /dev/null
@@ -0,0 +1,13 @@
+#include <stdio.h>
+
+void foo(const char *str, int n)
+{
+  printf("%d: %s\n", n, str);
+}
+
+int run_test()
+{
+  foo("A Space Odyssey", 2001);
+
+  return 0;
+}
index 5429487ad163c005ce0b727dfdb0c70f9adad32e..3a6f0afc8bec058b3caecad3b78625bdcfe7e5af 100644 (file)
@@ -9,6 +9,7 @@
 <testcase name="Instrumenting Advice">
   <plugin id="plugin-reinst1" source="plugin-reinst1.c" />
   <plugin id="plugin-reinst2" source="plugin-reinst2.c" />
+  <plugin id="plugin-reinst-dup" source="plugin-reinst-dup.c" />
   <run name="Attempt to instrument advice" target="reinst-target.c" hooks="reinst-hooks.c">
     <using plugin="plugin-reinst1" />
     <output>
       THX 1138
     </output>
   </run>
+  <run name="Attempt to instrument distributor assignment" target="reinst-dup-target.c" hooks="reinst-dup-hooks.c">
+    <using plugin="plugin-reinst-dup" />
+    <output>
+      In distributor.
+      2001: A Space Odyssey
+    </output>
+  </run>
 </testcase>