diff options
Diffstat (limited to 'gcc/tree-chkp.c')
-rw-r--r-- | gcc/tree-chkp.c | 69 |
1 files changed, 68 insertions, 1 deletions
diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c index 8b6381f..b666e97 100644 --- a/gcc/tree-chkp.c +++ b/gcc/tree-chkp.c @@ -2157,7 +2157,11 @@ static bool chkp_call_returns_bounds_p (gcall *call) { if (gimple_call_internal_p (call)) - return false; + { + if (gimple_call_internal_fn (call) == IFN_VA_ARG) + return true; + return false; + } if (gimple_call_builtin_p (call, BUILT_IN_CHKP_NARROW_PTR_BOUNDS) || chkp_gimple_call_builtin_p (call, BUILT_IN_CHKP_NARROW)) @@ -2490,6 +2494,69 @@ chkp_build_bndstx (tree addr, tree ptr, tree bounds, } } +/* This function is called when call statement + is inlined and therefore we can't use bndret + for its LHS anymore. Function fixes bndret + call using new RHS value if possible. */ +void +chkp_fixup_inlined_call (tree lhs, tree rhs) +{ + tree addr, bounds; + gcall *retbnd, *bndldx; + + if (!BOUNDED_P (lhs)) + return; + + /* Search for retbnd call. */ + retbnd = chkp_retbnd_call_by_val (lhs); + if (!retbnd) + return; + + /* Currently only handle cases when call is replaced + with a memory access. In this case bndret call + may be replaced with bndldx call. Otherwise we + have to search for bounds which may cause wrong + result due to various optimizations applied. */ + switch (TREE_CODE (rhs)) + { + case VAR_DECL: + if (DECL_REGISTER (rhs)) + return; + break; + + case MEM_REF: + break; + + case ARRAY_REF: + case COMPONENT_REF: + addr = get_base_address (rhs); + if (!DECL_P (addr) + && TREE_CODE (addr) != MEM_REF) + return; + if (DECL_P (addr) && DECL_REGISTER (addr)) + return; + break; + + default: + return; + } + + /* Create a new statements sequence with bndldx call. */ + gimple_stmt_iterator gsi = gsi_for_stmt (retbnd); + addr = build_fold_addr_expr (rhs); + chkp_build_bndldx (addr, lhs, &gsi); + bndldx = as_a <gcall *> (gsi_stmt (gsi)); + + /* Remove bndret call. */ + bounds = gimple_call_lhs (retbnd); + gsi = gsi_for_stmt (retbnd); + gsi_remove (&gsi, true); + + /* Link new bndldx call. */ + gimple_call_set_lhs (bndldx, bounds); + update_stmt (bndldx); +} + /* Compute bounds for pointer NODE which was assigned in assignment statement ASSIGN. Return computed bounds. */ static tree |