This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [CHKP] Support returned bounds in thunks expand
- From: Ilya Enkovich <enkovich dot gnu at gmail dot com>
- To: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 2 Apr 2015 17:49:21 +0300
- Subject: Re: [CHKP] Support returned bounds in thunks expand
- Authentication-results: sourceware.org; auth=none
- References: <20150306141531 dot GA27860 at msticlxl57 dot ims dot intel dot com>
Ping
2015-03-10 13:12 GMT+03:00 Ilya Enkovich <enkovich.gnu@gmail.com>:
> Hi,
>
> Currentl we loose returned bounds when functions are merged. This patch fixes it by adding returne bounds support for cgraph_node::expand_thunk. Bootstrapped and tested on x86_64-unknown-linux-gnu. OK for trunk?
>
> Thanks,
> Ilya
> --
> gcc/
>
> 2015-03-06 Ilya Enkovich <ilya.enkovich@intel.com>
>
> * cgraphunit.c (cgraph_node::expand_thunk): Build returned
> bounds for instrumented functions.
>
> gcc/testsuite/
>
> 2015-03-06 Ilya Enkovich <ilya.enkovich@intel.com>
>
> * gcc/testsuite/gcc.target/i386/thunk-retbnd.c: New.
>
>
> diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c
> index e640907..fc38e67 100644
> --- a/gcc/cgraphunit.c
> +++ b/gcc/cgraphunit.c
> @@ -1581,6 +1581,7 @@ cgraph_node::expand_thunk (bool output_asm_thunks, bool force_gimple_thunk)
> int i;
> tree resdecl;
> tree restmp = NULL;
> + tree resbnd = NULL;
>
> gcall *call;
> greturn *ret;
> @@ -1697,6 +1698,21 @@ cgraph_node::expand_thunk (bool output_asm_thunks, bool force_gimple_thunk)
> gsi_insert_after (&bsi, call, GSI_NEW_STMT);
> if (!alias_is_noreturn)
> {
> + if (instrumentation_clone
> + && !DECL_BY_REFERENCE (resdecl)
> + && restmp
> + && BOUNDED_P (restmp))
> + {
> + tree fn = targetm.builtin_chkp_function (BUILT_IN_CHKP_BNDRET);
> + gcall *retbnd = gimple_build_call (fn, 1, restmp);
> +
> + resbnd = create_tmp_reg (pointer_bounds_type_node, "retbnd");
> + gimple_call_set_lhs (retbnd, resbnd);
> +
> + gsi_insert_after (&bsi, retbnd, GSI_NEW_STMT);
> + create_edge (get_create (fn), retbnd, callees->count, callees->frequency);
> + }
> +
> if (restmp && !this_adjusting
> && (fixed_offset || virtual_offset))
> {
> @@ -1766,6 +1782,7 @@ cgraph_node::expand_thunk (bool output_asm_thunks, bool force_gimple_thunk)
> ret = gimple_build_return (restmp);
> else
> ret = gimple_build_return (resdecl);
> + gimple_return_set_retbnd (ret, resbnd);
>
> gsi_insert_after (&bsi, ret, GSI_NEW_STMT);
> }
> diff --git a/gcc/testsuite/gcc.target/i386/thunk-retbnd.c b/gcc/testsuite/gcc.target/i386/thunk-retbnd.c
> new file mode 100644
> index 0000000..d9bd031
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/thunk-retbnd.c
> @@ -0,0 +1,19 @@
> +/* { dg-do compile } */
> +/* { dg-require-effective-target mpx } */
> +/* { dg-options "-O2 -fcheck-pointer-bounds -mmpx -fdump-tree-optimized" } */
> +/* { dg-final { scan-tree-dump-times "return &glob," 2 "optimized" } } */
> +/* { dg-final { cleanup-tree-dump "optimized" } } */
> +
> +int glob;
> +
> +int *
> +test1 (void)
> +{
> + return &glob;
> +}
> +
> +int *
> +test2 (void)
> +{
> + return test1 ();
> +}