Hi, Currently instrumentation clone may be requested for a function which cannot be cloned and a thunk is created in such case. Thunk creation is bogus and cause original node and a clone to share arguments list (including bounds args). I don't think such thunks are actually useful and therefore restrict their creation. Also fix function pointers instrumentation to skip not instrumentable functions. Bootstrapped and regtested for x86_64-unknown-linux-gnu. Applied to trunk. Is it OK for gcc-5-branch?
Thanks, Ilya -- gcc/ 2015-06-18 Ilya Enkovich <enkovich....@gmail.com> PR middle-end/66567 * ipa-chkp.c (chkp_maybe_create_clone): Require functions to be instrumentable. * tree-chkp.c (chkp_replace_function_pointer): Use chkp_instrumentable_p instead of attribute check. gcc/testsuite/ 2015-06-18 Ilya Enkovich <enkovich....@gmail.com> PR middle-end/66567 * gcc.target/i386/mpx/pr66567.c: New test. diff --git a/gcc/ipa-chkp.c b/gcc/ipa-chkp.c index f3d7c73..c5e7147 100644 --- a/gcc/ipa-chkp.c +++ b/gcc/ipa-chkp.c @@ -565,25 +565,10 @@ chkp_maybe_create_clone (tree fndecl) if (gimple_has_body_p (fndecl)) { - /* If function will not be instrumented, then it's instrumented - version is a thunk for the original. */ - if (!chkp_instrumentable_p (fndecl)) - { - clone->remove_callees (); - clone->remove_all_references (); - clone->thunk.thunk_p = true; - clone->thunk.add_pointer_bounds_args = true; - clone->create_edge (node, NULL, 0, CGRAPH_FREQ_BASE); - /* Thunk shouldn't be a cdtor. */ - DECL_STATIC_CONSTRUCTOR (clone->decl) = 0; - DECL_STATIC_DESTRUCTOR (clone->decl) = 0; - } - else - { - tree_function_versioning (fndecl, new_decl, NULL, false, - NULL, false, NULL, NULL); - clone->lowered = true; - } + gcc_assert (chkp_instrumentable_p (fndecl)); + tree_function_versioning (fndecl, new_decl, NULL, false, + NULL, false, NULL, NULL); + clone->lowered = true; } /* New params are inserted after versioning because it diff --git a/gcc/testsuite/gcc.target/i386/mpx/pr66567.c b/gcc/testsuite/gcc.target/i386/mpx/pr66567.c new file mode 100644 index 0000000..5a7e2f2 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/mpx/pr66567.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-fcheck-pointer-bounds -mmpx" } */ + +void (*b) (); + +void fn1 (const int *p1) +{ + static void *a = &&conv_1234_123C; + conv_1234_123C: + ; +} + +void fn2 () +{ + b = fn1; +} diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c index 8edef48..e2612bd 100644 --- a/gcc/tree-chkp.c +++ b/gcc/tree-chkp.c @@ -4090,7 +4090,7 @@ chkp_replace_function_pointer (tree *op, int *walk_subtrees, void *data ATTRIBUTE_UNUSED) { if (TREE_CODE (*op) == FUNCTION_DECL - && !lookup_attribute ("bnd_legacy", DECL_ATTRIBUTES (*op)) + && chkp_instrumentable_p (*op) && (DECL_BUILT_IN_CLASS (*op) == NOT_BUILT_IN /* For builtins we replace pointers only for selected function and functions having definitions. */