Commit 855f036d by Ilya Enkovich Committed by Ilya Enkovich

re PR middle-end/66568 ([CHKP] internal compiler error: in expand_expr_addr_expr_1)

gcc/

	PR middle-end/66568
	* cfgexpand.c (expand_return): Handle missing bounds.
	(expand_gimple_stmt_1): Likewise.
	* tree-chkp.c (chkp_expand_zero_bounds): New.
	* tree-chkp.h (chkp_expand_zero_bounds): New.

gcc/testsuite/

	PR middle-end/66568
	* gcc.target/i386/mpx/pr66568.c: New test.

From-SVN: r224601
parent 847ffe17
2015-06-18 Ilya Enkovich <enkovich.gnu@gmail.com> 2015-06-18 Ilya Enkovich <enkovich.gnu@gmail.com>
PR middle-end/66568
* cfgexpand.c (expand_return): Handle missing bounds.
(expand_gimple_stmt_1): Likewise.
* tree-chkp.c (chkp_expand_zero_bounds): New.
* tree-chkp.h (chkp_expand_zero_bounds): New.
2015-06-18 Ilya Enkovich <enkovich.gnu@gmail.com>
PR middle-end/66567 PR middle-end/66567
* ipa-chkp.c (chkp_maybe_create_clone): Require * ipa-chkp.c (chkp_maybe_create_clone): Require
functions to be instrumentable. functions to be instrumentable.
......
...@@ -3134,18 +3134,25 @@ expand_return (tree retval, tree bounds) ...@@ -3134,18 +3134,25 @@ expand_return (tree retval, tree bounds)
bounds_rtl = DECL_BOUNDS_RTL (DECL_RESULT (current_function_decl)); bounds_rtl = DECL_BOUNDS_RTL (DECL_RESULT (current_function_decl));
if (bounds_rtl) if (bounds_rtl)
{ {
rtx addr, bnd; rtx addr = NULL;
rtx bnd = NULL;
if (bounds) if (bounds && bounds != error_mark_node)
{ {
bnd = expand_normal (bounds); bnd = expand_normal (bounds);
targetm.calls.store_returned_bounds (bounds_rtl, bnd); targetm.calls.store_returned_bounds (bounds_rtl, bnd);
} }
else if (REG_P (bounds_rtl)) else if (REG_P (bounds_rtl))
{ {
if (bounds)
bnd = chkp_expand_zero_bounds ();
else
{
addr = expand_normal (build_fold_addr_expr (retval_rhs)); addr = expand_normal (build_fold_addr_expr (retval_rhs));
addr = gen_rtx_MEM (Pmode, addr); addr = gen_rtx_MEM (Pmode, addr);
bnd = targetm.calls.load_bounds_for_arg (addr, NULL, NULL); bnd = targetm.calls.load_bounds_for_arg (addr, NULL, NULL);
}
targetm.calls.store_returned_bounds (bounds_rtl, bnd); targetm.calls.store_returned_bounds (bounds_rtl, bnd);
} }
else else
...@@ -3154,15 +3161,23 @@ expand_return (tree retval, tree bounds) ...@@ -3154,15 +3161,23 @@ expand_return (tree retval, tree bounds)
gcc_assert (GET_CODE (bounds_rtl) == PARALLEL); gcc_assert (GET_CODE (bounds_rtl) == PARALLEL);
if (bounds)
bnd = chkp_expand_zero_bounds ();
else
{
addr = expand_normal (build_fold_addr_expr (retval_rhs)); addr = expand_normal (build_fold_addr_expr (retval_rhs));
addr = gen_rtx_MEM (Pmode, addr); addr = gen_rtx_MEM (Pmode, addr);
}
for (n = 0; n < XVECLEN (bounds_rtl, 0); n++) for (n = 0; n < XVECLEN (bounds_rtl, 0); n++)
{ {
rtx offs = XEXP (XVECEXP (bounds_rtl, 0, n), 1);
rtx slot = XEXP (XVECEXP (bounds_rtl, 0, n), 0); rtx slot = XEXP (XVECEXP (bounds_rtl, 0, n), 0);
if (!bounds)
{
rtx offs = XEXP (XVECEXP (bounds_rtl, 0, n), 1);
rtx from = adjust_address (addr, Pmode, INTVAL (offs)); rtx from = adjust_address (addr, Pmode, INTVAL (offs));
rtx bnd = targetm.calls.load_bounds_for_arg (from, NULL, NULL); bnd = targetm.calls.load_bounds_for_arg (from, NULL, NULL);
}
targetm.calls.store_returned_bounds (slot, bnd); targetm.calls.store_returned_bounds (slot, bnd);
} }
} }
...@@ -3259,6 +3274,8 @@ expand_gimple_stmt_1 (gimple stmt) ...@@ -3259,6 +3274,8 @@ expand_gimple_stmt_1 (gimple stmt)
break; break;
case GIMPLE_RETURN: case GIMPLE_RETURN:
{
tree bnd = gimple_return_retbnd (as_a <greturn *> (stmt));
op0 = gimple_return_retval (as_a <greturn *> (stmt)); op0 = gimple_return_retval (as_a <greturn *> (stmt));
if (op0 && op0 != error_mark_node) if (op0 && op0 != error_mark_node)
...@@ -3281,11 +3298,16 @@ expand_gimple_stmt_1 (gimple stmt) ...@@ -3281,11 +3298,16 @@ expand_gimple_stmt_1 (gimple stmt)
op0 = build2 (MODIFY_EXPR, TREE_TYPE (result), op0 = build2 (MODIFY_EXPR, TREE_TYPE (result),
result, op0); result, op0);
} }
/* Mark we have return statement with missing bounds. */
if (!bnd && chkp_function_instrumented_p (cfun->decl))
bnd = error_mark_node;
} }
if (!op0) if (!op0)
expand_null_return (); expand_null_return ();
else else
expand_return (op0, gimple_return_retbnd (stmt)); expand_return (op0, bnd);
}
break; break;
case GIMPLE_ASSIGN: case GIMPLE_ASSIGN:
......
2015-06-18 Ilya Enkovich <enkovich.gnu@gmail.com> 2015-06-18 Ilya Enkovich <enkovich.gnu@gmail.com>
PR middle-end/66568
* gcc.target/i386/mpx/pr66568.c: New test.
2015-06-18 Ilya Enkovich <enkovich.gnu@gmail.com>
PR middle-end/66567 PR middle-end/66567
* gcc.target/i386/mpx/pr66567.c: New test. * gcc.target/i386/mpx/pr66567.c: New test.
......
/* { dg-do compile } */
/* { dg-require-effective-target fpic } */
/* { dg-options "-O2 -fcheck-pointer-bounds -mmpx -O2 -fPIC" } */
int a, b, c;
void *set_test () {
if (b)
a ? exit (0) : exit (1);
b = c;
}
...@@ -466,6 +466,21 @@ chkp_gimple_call_builtin_p (gimple call, ...@@ -466,6 +466,21 @@ chkp_gimple_call_builtin_p (gimple call,
return false; return false;
} }
/* Emit code to build zero bounds and return RTL holding
the result. */
rtx
chkp_expand_zero_bounds ()
{
tree zero_bnd;
if (flag_chkp_use_static_const_bounds)
zero_bnd = chkp_get_zero_bounds_var ();
else
zero_bnd = chkp_build_make_bounds_call (integer_zero_node,
integer_zero_node);
return expand_normal (zero_bnd);
}
/* Emit code to store zero bounds for PTR located at MEM. */ /* Emit code to store zero bounds for PTR located at MEM. */
void void
chkp_expand_bounds_reset_for_mem (tree mem, tree ptr) chkp_expand_bounds_reset_for_mem (tree mem, tree ptr)
......
...@@ -53,6 +53,7 @@ extern void chkp_copy_bounds_for_assign (gimple assign, ...@@ -53,6 +53,7 @@ extern void chkp_copy_bounds_for_assign (gimple assign,
struct cgraph_edge *edge); struct cgraph_edge *edge);
extern bool chkp_gimple_call_builtin_p (gimple call, extern bool chkp_gimple_call_builtin_p (gimple call,
enum built_in_function code); enum built_in_function code);
extern rtx chkp_expand_zero_bounds (void);
extern void chkp_expand_bounds_reset_for_mem (tree mem, tree ptr); extern void chkp_expand_bounds_reset_for_mem (tree mem, tree ptr);
extern tree chkp_insert_retbnd_call (tree bndval, tree retval, extern tree chkp_insert_retbnd_call (tree bndval, tree retval,
gimple_stmt_iterator *gsi); gimple_stmt_iterator *gsi);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment