Re: [PATCH, Pointer Bounds Checker 14/x] Passes [7/n] Instrument params
On 10 Oct 12:10, Jeff Law wrote: > On 10/08/14 13:06, Ilya Enkovich wrote: > >Hi, > > > >This patch adds bounds initialization for address taken input arguments. > > > >Thanks, > >Ilya > >-- > >2014-10-08 Ilya Enkovich > > > > * tree-chkp.c (chkp_instrument_function): Store bounds for > > address taken args. > > > > > >diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c > >index 6bbceb0..5443950 100644 > >--- a/gcc/tree-chkp.c > >+++ b/gcc/tree-chkp.c > >@@ -3758,6 +3758,51 @@ chkp_instrument_function (void) > >bb = next; > > } > >while (bb); > >+ > >+ /* Some input params may have bounds and be address taken. In this case > >+ we should store incomping bounds into bounds table. */ > s/incomping/incoming/ > > With that nit fixed this is OK. > > jeff > Here is a fixed version. Thanks, Ilya -- diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c index 0d4577d1..53b3386 100644 --- a/gcc/tree-chkp.c +++ b/gcc/tree-chkp.c @@ -3758,6 +3758,51 @@ chkp_instrument_function (void) bb = next; } while (bb); + + /* Some input params may have bounds and be address taken. In this case + we should store incoming bounds into bounds table. */ + tree arg; + if (flag_chkp_store_bounds) +for (arg = DECL_ARGUMENTS (cfun->decl); arg; arg = DECL_CHAIN (arg)) + if (TREE_ADDRESSABLE (arg)) + { + if (BOUNDED_P (arg)) + { + tree bounds = chkp_get_next_bounds_parm (arg); + tree def_ptr = ssa_default_def (cfun, arg); + gimple_stmt_iterator iter + = gsi_start_bb (chkp_get_entry_block ()); + chkp_build_bndstx (chkp_build_addr_expr (arg), +def_ptr ? def_ptr : arg, +bounds, &iter); + + /* Skip bounds arg. */ + arg = TREE_CHAIN (arg); + } + else if (chkp_type_has_pointer (TREE_TYPE (arg))) + { + tree orig_arg = arg; + bitmap slots = chkp_find_bound_slots (TREE_TYPE (arg)); + gimple_stmt_iterator iter + = gsi_start_bb (chkp_get_entry_block ()); + bitmap_iterator bi; + unsigned bnd_no; + + EXECUTE_IF_SET_IN_BITMAP (slots, 0, bnd_no, bi) + { + tree bounds = chkp_get_next_bounds_parm (arg); + HOST_WIDE_INT offs = bnd_no * POINTER_SIZE / BITS_PER_UNIT; + tree addr = chkp_build_addr_expr (orig_arg); + tree ptr = build2 (MEM_REF, ptr_type_node, addr, +build_int_cst (ptr_type_node, offs)); + chkp_build_bndstx (chkp_build_addr_expr (ptr), ptr, +bounds, &iter); + + arg = DECL_CHAIN (arg); + } + BITMAP_FREE (slots); + } + } } /* Initialize pass. */
Re: [PATCH, Pointer Bounds Checker 14/x] Passes [7/n] Instrument params
On 10/08/14 13:06, Ilya Enkovich wrote: Hi, This patch adds bounds initialization for address taken input arguments. Thanks, Ilya -- 2014-10-08 Ilya Enkovich * tree-chkp.c (chkp_instrument_function): Store bounds for address taken args. diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c index 6bbceb0..5443950 100644 --- a/gcc/tree-chkp.c +++ b/gcc/tree-chkp.c @@ -3758,6 +3758,51 @@ chkp_instrument_function (void) bb = next; } while (bb); + + /* Some input params may have bounds and be address taken. In this case + we should store incomping bounds into bounds table. */ s/incomping/incoming/ With that nit fixed this is OK. jeff
[PATCH, Pointer Bounds Checker 14/x] Passes [7/n] Instrument params
Hi, This patch adds bounds initialization for address taken input arguments. Thanks, Ilya -- 2014-10-08 Ilya Enkovich * tree-chkp.c (chkp_instrument_function): Store bounds for address taken args. diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c index 6bbceb0..5443950 100644 --- a/gcc/tree-chkp.c +++ b/gcc/tree-chkp.c @@ -3758,6 +3758,51 @@ chkp_instrument_function (void) bb = next; } while (bb); + + /* Some input params may have bounds and be address taken. In this case + we should store incomping bounds into bounds table. */ + tree arg; + if (flag_chkp_store_bounds) +for (arg = DECL_ARGUMENTS (cfun->decl); arg; arg = DECL_CHAIN (arg)) + if (TREE_ADDRESSABLE (arg)) + { + if (BOUNDED_P (arg)) + { + tree bounds = chkp_get_next_bounds_parm (arg); + tree def_ptr = ssa_default_def (cfun, arg); + gimple_stmt_iterator iter + = gsi_start_bb (chkp_get_entry_block ()); + chkp_build_bndstx (chkp_build_addr_expr (arg), +def_ptr ? def_ptr : arg, +bounds, &iter); + + /* Skip bounds arg. */ + arg = TREE_CHAIN (arg); + } + else if (chkp_type_has_pointer (TREE_TYPE (arg))) + { + tree orig_arg = arg; + bitmap slots = chkp_find_bound_slots (TREE_TYPE (arg)); + gimple_stmt_iterator iter + = gsi_start_bb (chkp_get_entry_block ()); + bitmap_iterator bi; + unsigned bnd_no; + + EXECUTE_IF_SET_IN_BITMAP (slots, 0, bnd_no, bi) + { + tree bounds = chkp_get_next_bounds_parm (arg); + HOST_WIDE_INT offs = bnd_no * POINTER_SIZE / BITS_PER_UNIT; + tree addr = chkp_build_addr_expr (orig_arg); + tree ptr = build2 (MEM_REF, ptr_type_node, addr, +build_int_cst (ptr_type_node, offs)); + chkp_build_bndstx (chkp_build_addr_expr (ptr), ptr, +bounds, &iter); + + arg = DECL_CHAIN (arg); + } + BITMAP_FREE (slots); + } + } } /* Initialize pass. */