From 01156003a987af28c1432f247471b2192566612a Mon Sep 17 00:00:00 2001 From: Ilya Enkovich Date: Mon, 18 Nov 2013 12:30:52 +0000 Subject: [PATCH] builtin-types.def (BT_FN_PTR_CONST_PTR_VAR): New. * builtin-types.def (BT_FN_PTR_CONST_PTR_VAR): New. * chkp-builtins.def (BUILT_IN_CHKP_BIND_BOUNDS): New. * cfgexpand.c (expand_call_stmt): Expand BUILT_IN_CHKP_BIND_BOUNDS. * gimple.c (gimple_call_get_nobnd_arg_index): Remove. * gimple.h (gf_mask): Add GF_CALL_WITH_BOUNDS. (gimple_call_with_bounds_p): New. (gimple_call_set_with_bounds): New. (gimple_call_num_nobnd_args): Remove. (gimple_call_nobnd_arg): Remove. * tree.h (CALL_WITH_BOUNDS_P): New. * rtl.h (CALL_EXPR_WITH_BOUNDS_P): New. From-SVN: r204947 --- gcc/ChangeLog | 14 ++++++++++++++ gcc/builtin-types.def | 2 ++ gcc/cfgexpand.c | 16 +++++++++++++--- gcc/chkp-builtins.def | 3 +++ gcc/gimple.c | 20 ------------------- gcc/gimple.h | 53 +++++++++++++++++++++++++-------------------------- gcc/rtl.h | 7 ++++++- gcc/tree.h | 3 +++ 8 files changed, 67 insertions(+), 51 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8bb1a44..72e707a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,17 @@ +2013-11-18 Ilya Enkovich + + * builtin-types.def (BT_FN_PTR_CONST_PTR_VAR): New. + * chkp-builtins.def (BUILT_IN_CHKP_BIND_BOUNDS): New. + * cfgexpand.c (expand_call_stmt): Expand BUILT_IN_CHKP_BIND_BOUNDS. + * gimple.c (gimple_call_get_nobnd_arg_index): Remove. + * gimple.h (gf_mask): Add GF_CALL_WITH_BOUNDS. + (gimple_call_with_bounds_p): New. + (gimple_call_set_with_bounds): New. + (gimple_call_num_nobnd_args): Remove. + (gimple_call_nobnd_arg): Remove. + * tree.h (CALL_WITH_BOUNDS_P): New. + * rtl.h (CALL_EXPR_WITH_BOUNDS_P): New. + 2013-11-18 Trevor Saunders * cgraph.h (symtab_node_asm_name): Rename to symtab_node::asm_name. diff --git a/gcc/builtin-types.def b/gcc/builtin-types.def index 1f9ae4e..e7bfaf9 100644 --- a/gcc/builtin-types.def +++ b/gcc/builtin-types.def @@ -542,6 +542,8 @@ DEF_FUNCTION_TYPE_VAR_1 (BT_FN_INT_CONST_STRING_VAR, BT_INT, BT_CONST_STRING) DEF_FUNCTION_TYPE_VAR_1 (BT_FN_UINT32_UINT32_VAR, BT_UINT32, BT_UINT32) +DEF_FUNCTION_TYPE_VAR_1 (BT_FN_PTR_CONST_PTR_VAR, + BT_PTR, BT_CONST_PTR) DEF_FUNCTION_TYPE_VAR_2 (BT_FN_INT_FILEPTR_CONST_STRING_VAR, BT_INT, BT_FILEPTR, BT_CONST_STRING) diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c index 3100688..124a4b8 100644 --- a/gcc/cfgexpand.c +++ b/gcc/cfgexpand.c @@ -2154,12 +2154,22 @@ expand_call_stmt (gimple stmt) return; } - exp = build_vl_exp (CALL_EXPR, gimple_call_num_args (stmt) + 3); - - CALL_EXPR_FN (exp) = gimple_call_fn (stmt); decl = gimple_call_fndecl (stmt); builtin_p = decl && DECL_BUILT_IN (decl); + /* Bind bounds call is expanded as assignment. */ + if (builtin_p + && DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL + && DECL_FUNCTION_CODE (decl) == BUILT_IN_CHKP_BIND_BOUNDS) + { + expand_assignment (gimple_call_lhs (stmt), + gimple_call_arg (stmt, 0), false); + return; + } + + exp = build_vl_exp (CALL_EXPR, gimple_call_num_args (stmt) + 3); + CALL_EXPR_FN (exp) = gimple_call_fn (stmt); + /* If this is not a builtin function, the function type through which the call is made may be different from the type of the function. */ if (!builtin_p) diff --git a/gcc/chkp-builtins.def b/gcc/chkp-builtins.def index d19b541..b920950 100644 --- a/gcc/chkp-builtins.def +++ b/gcc/chkp-builtins.def @@ -42,6 +42,9 @@ DEF_BUILTIN_STUB (BUILT_IN_CHKP_EXTRACT_LOWER, "__chkp_extract_lower") DEF_BUILTIN_STUB (BUILT_IN_CHKP_EXTRACT_UPPER, "__chkp_extract_upper") DEF_BUILTIN_STUB (BUILT_IN_CHKP_NARROW, "__chkp_narrow") +/* Builtins to bind bounds to call arguments. */ +DEF_CHKP_BUILTIN (BUILT_IN_CHKP_BIND_BOUNDS, "__chkp_bind_bounds", BT_FN_PTR_CONST_PTR_VAR, ATTR_CONST_NOTHROW_LEAF_LIST) + /* Pointer Bounds Checker builtins for users. Only BUILT_IN_CHKP_SET_PTR_BOUNDS may be redefined by target. Other builtins calls are expanded diff --git a/gcc/gimple.c b/gcc/gimple.c index f42d921..2d64261 100644 --- a/gcc/gimple.c +++ b/gcc/gimple.c @@ -365,26 +365,6 @@ gimple_build_call_from_tree (tree t) } -/* Return index of INDEX's non bound argument of the call. */ - -unsigned -gimple_call_get_nobnd_arg_index (const_gimple gs, unsigned index) -{ - unsigned num_args = gimple_call_num_args (gs); - for (unsigned n = 0; n < num_args; n++) - { - if (POINTER_BOUNDS_P (gimple_call_arg (gs, n))) - continue; - else if (index) - index--; - else - return n; - } - - gcc_unreachable (); -} - - /* Build a GIMPLE_ASSIGN statement. LHS of the assignment. diff --git a/gcc/gimple.h b/gcc/gimple.h index 022bac9..4234c3c 100644 --- a/gcc/gimple.h +++ b/gcc/gimple.h @@ -101,6 +101,7 @@ enum gf_mask { GF_CALL_NOTHROW = 1 << 4, GF_CALL_ALLOCA_FOR_VAR = 1 << 5, GF_CALL_INTERNAL = 1 << 6, + GF_CALL_WITH_BOUNDS = 1 << 7, GF_OMP_PARALLEL_COMBINED = 1 << 0, GF_OMP_FOR_KIND_MASK = 3 << 0, GF_OMP_FOR_KIND_FOR = 0 << 0, @@ -737,7 +738,6 @@ gimple gimple_build_call_valist (tree, unsigned, va_list); gimple gimple_build_call_internal (enum internal_fn, unsigned, ...); gimple gimple_build_call_internal_vec (enum internal_fn, vec ); gimple gimple_build_call_from_tree (tree); -extern unsigned gimple_call_get_nobnd_arg_index (const_gimple, unsigned); gimple gimple_build_assign_stat (tree, tree MEM_STAT_DECL); #define gimple_build_assign(l,r) gimple_build_assign_stat (l, r MEM_STAT_INFO) gimple gimple_build_assign_with_ops (enum tree_code, tree, @@ -1960,6 +1960,31 @@ gimple_call_internal_p (const_gimple gs) } +/* Return true if call GS is marked as instrumented by + Pointer Bounds Checker. */ + +static inline bool +gimple_call_with_bounds_p (const_gimple gs) +{ + GIMPLE_CHECK (gs, GIMPLE_CALL); + return (gs->gsbase.subcode & GF_CALL_WITH_BOUNDS) != 0; +} + + +/* If INSTRUMENTED_P is true, marm statement GS as instrumented by + Pointer Bounds Checker. */ + +static inline void +gimple_call_set_with_bounds (gimple gs, bool with_bounds) +{ + GIMPLE_CHECK (gs, GIMPLE_CALL); + if (with_bounds) + gs->gsbase.subcode |= GF_CALL_WITH_BOUNDS; + else + gs->gsbase.subcode &= ~GF_CALL_WITH_BOUNDS; +} + + /* Return the target of internal call GS. */ static inline enum internal_fn @@ -2125,32 +2150,6 @@ gimple_call_arg (const_gimple gs, unsigned index) } -/* Return the number of arguments used by call statement GS - ignoring bound ones. */ - -static inline unsigned -gimple_call_num_nobnd_args (const_gimple gs) -{ - unsigned num_args = gimple_call_num_args (gs); - unsigned res = num_args; - for (unsigned n = 0; n < num_args; n++) - if (POINTER_BOUNDS_P (gimple_call_arg (gs, n))) - res--; - return res; -} - - -/* Return INDEX's call argument ignoring bound ones. */ -static inline tree -gimple_call_nobnd_arg (const_gimple gs, unsigned index) -{ - /* No bound args may exist if pointers checker is off. */ - if (!flag_check_pointer_bounds) - return gimple_call_arg (gs, index); - return gimple_call_arg (gs, gimple_call_get_nobnd_arg_index (gs, index)); -} - - /* Return a pointer to the argument at position INDEX for call statement GS. */ diff --git a/gcc/rtl.h b/gcc/rtl.h index 247a0d0..bab5b7c 100644 --- a/gcc/rtl.h +++ b/gcc/rtl.h @@ -266,7 +266,8 @@ struct GTY((chain_next ("RTX_NEXT (&%h)"), In a CODE_LABEL, part of the two-bit alternate entry field. 1 in a CONCAT is VAL_EXPR_IS_COPIED in var-tracking.c. 1 in a VALUE is SP_BASED_VALUE_P in cselib.c. - 1 in a SUBREG generated by LRA for reload insns. */ + 1 in a SUBREG generated by LRA for reload insns. + 1 in a CALL for calls instrumented by Pointer Bounds Checker. */ unsigned int jump : 1; /* In a CODE_LABEL, part of the two-bit alternate entry field. 1 in a MEM if it cannot trap. @@ -1420,6 +1421,10 @@ do { \ #define LRA_SUBREG_P(RTX) \ (RTL_FLAG_CHECK1 ("LRA_SUBREG_P", (RTX), SUBREG)->jump) +/* True if call is instrumented by Pointer Bounds Checker. */ +#define CALL_EXPR_WITH_BOUNDS_P(RTX) \ + (RTL_FLAG_CHECK1 ("CALL_EXPR_WITH_BOUNDS_P", (RTX), CALL)->jump) + /* Access various components of an ASM_OPERANDS rtx. */ #define ASM_OPERANDS_TEMPLATE(RTX) XCSTR (RTX, 0, ASM_OPERANDS) diff --git a/gcc/tree.h b/gcc/tree.h index bc6699d..dee15be 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -831,6 +831,9 @@ extern void omp_clause_range_check_failed (const_tree, const char *, int, #define CALL_ALLOCA_FOR_VAR_P(NODE) \ (CALL_EXPR_CHECK (NODE)->base.protected_flag) +/* In a CALL_EXPR, means call was instrumented by Pointer Bounds Checker. */ +#define CALL_WITH_BOUNDS_P(NODE) (CALL_EXPR_CHECK (NODE)->base.deprecated_flag) + /* In a type, nonzero means that all objects of the type are guaranteed by the language or front-end to be properly aligned, so we can indicate that a MEM of this type is aligned at least to the alignment of the type, even if it -- 2.7.4