From: Jakub Jelinek Date: Thu, 9 Feb 2012 21:38:13 +0000 (+0100) Subject: backport: re PR libmudflap/40778 (Mudflap instrumentation missing in cloned function.) X-Git-Tag: releases/gcc-4.5.4~228 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bbd746836e838518b421bf0ad55a28275e753598;p=thirdparty%2Fgcc.git backport: re PR libmudflap/40778 (Mudflap instrumentation missing in cloned function.) Backported from mainline 2012-01-19 Jakub Jelinek PR libmudflap/40778 * tree-mudflap.c (mf_artificial): New function. (execute_mudflap_function_ops, execute_mudflap_function_decls, mx_register_decls, mudflap_enqueue_decl): Use it. * testsuite/libmudflap.c/fail68-frag.c: New test. From-SVN: r184073 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index fe4c69ef8ae9..eaa27374ff7e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,6 +1,13 @@ 2012-02-09 Jakub Jelinek Backported from mainline + 2012-01-19 Jakub Jelinek + + PR libmudflap/40778 + * tree-mudflap.c (mf_artificial): New function. + (execute_mudflap_function_ops, execute_mudflap_function_decls, + mx_register_decls, mudflap_enqueue_decl): Use it. + 2012-01-05 Jakub Jelinek PR rtl-optimization/51767 diff --git a/gcc/tree-mudflap.c b/gcc/tree-mudflap.c index 590f7c358d9a..89b7b459b566 100644 --- a/gcc/tree-mudflap.c +++ b/gcc/tree-mudflap.c @@ -72,6 +72,13 @@ static tree mx_xfn_xform_decls (gimple_stmt_iterator *, bool *, static gimple_seq mx_register_decls (tree, gimple_seq, location_t); static unsigned int execute_mudflap_function_decls (void); +/* Return true if DECL is artificial stub that shouldn't be instrumented by + mf. We should instrument clones of non-artificial functions. */ +static inline bool +mf_artificial (const_tree decl) +{ + return DECL_ARTIFICIAL (DECL_ORIGIN (decl)); +} /* ------------------------------------------------------------------------ */ /* Some generally helpful functions for mudflap instrumentation. */ @@ -437,8 +444,8 @@ execute_mudflap_function_ops (void) /* 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)) + if (mf_marked_p (current_function_decl) + || mf_artificial (current_function_decl)) return 0; push_gimplify_context (&gctx); @@ -1026,8 +1033,8 @@ execute_mudflap_function_decls (void) /* 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)) + if (mf_marked_p (current_function_decl) + || mf_artificial (current_function_decl)) return 0; push_gimplify_context (&gctx); @@ -1109,7 +1116,7 @@ mx_register_decls (tree decl, gimple_seq seq, location_t location) /* Add the __mf_register call at the current appending point. */ if (gsi_end_p (initially_stmts)) { - if (!DECL_ARTIFICIAL (decl)) + if (!mf_artificial (decl)) warning (OPT_Wmudflap, "mudflap cannot track %qE in stub function", DECL_NAME (decl)); @@ -1280,7 +1287,7 @@ mudflap_enqueue_decl (tree obj) during mudflap_finish_file (). That would confuse the user, since the text would refer to variables that don't show up in the user's source code. */ - if (DECL_P (obj) && DECL_EXTERNAL (obj) && DECL_ARTIFICIAL (obj)) + if (DECL_P (obj) && DECL_EXTERNAL (obj) && mf_artificial (obj)) return; VEC_safe_push (tree, gc, deferred_static_decls, obj); diff --git a/libmudflap/ChangeLog b/libmudflap/ChangeLog index 4a12de85a852..fc7dd2003baa 100644 --- a/libmudflap/ChangeLog +++ b/libmudflap/ChangeLog @@ -1,3 +1,11 @@ +2012-02-09 Jakub Jelinek + + Backported from mainline + 2012-01-19 Jakub Jelinek + + PR libmudflap/40778 + * testsuite/libmudflap.c/fail68-frag.c: New test. + 2011-04-28 Release Manager * GCC 4.5.3 released. diff --git a/libmudflap/testsuite/libmudflap.c/fail68-frag.c b/libmudflap/testsuite/libmudflap.c/fail68-frag.c new file mode 100644 index 000000000000..7b2f8cf2cb04 --- /dev/null +++ b/libmudflap/testsuite/libmudflap.c/fail68-frag.c @@ -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 *-*-* } } */