Instrument function clones using mudflap (PR libmudflap/40778)

Submitted by Jakub Jelinek on Dec. 16, 2010, 9:55 p.m.

Details

Message ID 20101216215553.GC2198@tyan-ft48-01.lab.bos.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Dec. 16, 2010, 9:55 p.m.
Hi!

As discussed in the PR, clones are DECL_ARTIFICIAL, so
execute_mudflap_function_ops pass wasn't done on them.  Skipping
the instrumentation of really artificial functions is ok, but
clones (and OpenMP functions etc.) are really user routines or parts
thereof.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2010-12-16  Jakub Jelinek  <jakub@redhat.com>

	PR libmudflap/40778
	* tree-mudflap.c (execute_mudflap_function_ops): Instrument
	even artificial functions, if their DECL_ORIGIN is not artificial.

	* testsuite/libmudflap.c/fail68-frag.c: New test.


	Jakub

Comments

Richard Guenther Dec. 18, 2010, 8:32 p.m.
On Thu, Dec 16, 2010 at 10:55 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> As discussed in the PR, clones are DECL_ARTIFICIAL, so
> execute_mudflap_function_ops pass wasn't done on them.  Skipping
> the instrumentation of really artificial functions is ok, but
> clones (and OpenMP functions etc.) are really user routines or parts
> thereof.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?

Hmm, instead of tree flags don't we have some cgraph state we can query?
Why do we not want to instrument compiler-generated functions?

Richard.

> 2010-12-16  Jakub Jelinek  <jakub@redhat.com>
>
>        PR libmudflap/40778
>        * tree-mudflap.c (execute_mudflap_function_ops): Instrument
>        even artificial functions, if their DECL_ORIGIN is not artificial.
>
>        * testsuite/libmudflap.c/fail68-frag.c: New test.
>
> --- gcc/tree-mudflap.c.jj       2010-12-02 11:51:32.000000000 +0100
> +++ gcc/tree-mudflap.c  2010-12-16 18:04:49.000000000 +0100
> @@ -411,9 +411,11 @@ execute_mudflap_function_ops (void)
>   struct gimplify_ctx gctx;
>
>   /* Don't instrument functions such as the synthetic constructor
> -     built during mudflap_finish_file.  */
> -  if (mf_marked_p (current_function_decl) ||
> -      DECL_ARTIFICIAL (current_function_decl))
> +     built during mudflap_finish_file.  Do instrument clones or
> +     other artificial functions created from user code.  */
> +  if (mf_marked_p (current_function_decl)
> +      || (DECL_ARTIFICIAL (current_function_decl)
> +         && DECL_ARTIFICIAL (DECL_ORIGIN (current_function_decl))))
>     return 0;
>
>   push_gimplify_context (&gctx);
> --- libmudflap/testsuite/libmudflap.c/fail68-frag.c.jj  2010-12-16 17:15:40.000000000 +0100
> +++ libmudflap/testsuite/libmudflap.c/fail68-frag.c     2010-12-16 17:26:16.000000000 +0100
> @@ -0,0 +1,27 @@
> +/* PR libmudflap/40778 */
> +
> +char p[32];
> +static int j;
> +
> +__attribute__((noinline))
> +static void foo (int i)
> +{
> +  if (j++ == 0)
> +    p[i + 4] = 12;
> +  else
> +    p[i - 4] = 13;
> +}
> +
> +int
> +main ()
> +{
> +  foo (30);
> +  foo (30);
> +  foo (30);
> +  return 0;
> +}
> +
> +/* { dg-output "mudflap violation 1.*" } */
> +/* { dg-output "Nearby object 1.*" } */
> +/* { dg-output "mudflap object.*name.*p" } */
> +/* { dg-do run { xfail *-*-* } } */
>
>        Jakub
>
Jeff Law Dec. 20, 2010, 5:01 a.m.
On 12/16/10 14:55, Jakub Jelinek wrote:
> Hi!
>
> As discussed in the PR, clones are DECL_ARTIFICIAL, so
> execute_mudflap_function_ops pass wasn't done on them.  Skipping
> the instrumentation of really artificial functions is ok, but
> clones (and OpenMP functions etc.) are really user routines or parts
> thereof.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?
>
> 2010-12-16  Jakub Jelinek<jakub@redhat.com>
>
> 	PR libmudflap/40778
> 	* tree-mudflap.c (execute_mudflap_function_ops): Instrument
> 	even artificial functions, if their DECL_ORIGIN is not artificial.
>
> 	* testsuite/libmudflap.c/fail68-frag.c: New test.
OK.
jeff

Patch hide | download patch | download mbox

--- gcc/tree-mudflap.c.jj	2010-12-02 11:51:32.000000000 +0100
+++ gcc/tree-mudflap.c	2010-12-16 18:04:49.000000000 +0100
@@ -411,9 +411,11 @@  execute_mudflap_function_ops (void)
   struct gimplify_ctx gctx;
 
   /* Don't instrument functions such as the synthetic constructor
-     built during mudflap_finish_file.  */
-  if (mf_marked_p (current_function_decl) ||
-      DECL_ARTIFICIAL (current_function_decl))
+     built during mudflap_finish_file.  Do instrument clones or
+     other artificial functions created from user code.  */
+  if (mf_marked_p (current_function_decl)
+      || (DECL_ARTIFICIAL (current_function_decl)
+	  && DECL_ARTIFICIAL (DECL_ORIGIN (current_function_decl))))
     return 0;
 
   push_gimplify_context (&gctx);
--- libmudflap/testsuite/libmudflap.c/fail68-frag.c.jj	2010-12-16 17:15:40.000000000 +0100
+++ libmudflap/testsuite/libmudflap.c/fail68-frag.c	2010-12-16 17:26:16.000000000 +0100
@@ -0,0 +1,27 @@ 
+/* PR libmudflap/40778 */
+
+char p[32];
+static int j;
+
+__attribute__((noinline))
+static void foo (int i)
+{
+  if (j++ == 0)
+    p[i + 4] = 12;
+  else
+    p[i - 4] = 13;
+}
+
+int
+main ()
+{
+  foo (30);
+  foo (30);
+  foo (30);
+  return 0;
+}
+
+/* { dg-output "mudflap violation 1.*" } */
+/* { dg-output "Nearby object 1.*" } */
+/* { dg-output "mudflap object.*name.*p" } */
+/* { dg-do run { xfail *-*-* } } */