Ping
2015-03-10 13:12 GMT+03:00 Ilya Enkovich <enkovich....@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.enkov...@intel.com> > > * cgraphunit.c (cgraph_node::expand_thunk): Build returned > bounds for instrumented functions. > > gcc/testsuite/ > > 2015-03-06 Ilya Enkovich <ilya.enkov...@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 (); > +}