From 17cbb388d3baaa784753a300e7eb86cb48b0cb4b Mon Sep 17 00:00:00 2001 From: bellard Date: Sat, 13 Jul 2002 15:55:38 +0000 Subject: [PATCH] optimized bound checking --- tcc.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tcc.c b/tcc.c index 8494e5a0..0554cd4f 100644 --- a/tcc.c +++ b/tcc.c @@ -286,6 +286,8 @@ struct TCCState { char/short stored in integer registers) */ #define VT_MUSTBOUND 0x0800 /* bound checking must be done before dereferencing value */ +#define VT_BOUNDED 0x8000 /* value is bounded. The address of the + bounding function call point is in vc */ #define VT_LVAL_BYTE 0x1000 /* lvalue is a byte */ #define VT_LVAL_SHORT 0x2000 /* lvalue is a short */ #define VT_LVAL_UNSIGNED 0x4000 /* lvalue is unsigned */ @@ -2660,12 +2662,16 @@ void gbound(void) vtop->r &= ~VT_MUSTBOUND; /* if lvalue, then use checking code before dereferencing */ if (vtop->r & VT_LVAL) { - lval_type = vtop->r & (VT_LVAL_TYPE | VT_LVAL); - gaddrof(); - vpushi(0); - gen_bounded_ptr_add1(); - gen_bounded_ptr_add2(1); - vtop->r |= lval_type; + /* if not VT_BOUNDED value, then make one */ + if (!(vtop->r & VT_BOUNDED)) { + lval_type = vtop->r & (VT_LVAL_TYPE | VT_LVAL); + gaddrof(); + vpushi(0); + gen_bounded_ptr_add(); + vtop->r |= lval_type; + } + /* then check for dereferencing */ + gen_bounded_ptr_deref(); } } #endif @@ -3365,9 +3371,8 @@ void gen_op(int op) vswap(); gen_op('-'); } - gen_bounded_ptr_add1(); - gen_bounded_ptr_add2(0); - } else + gen_bounded_ptr_add(); + } else #endif { gen_opic(op); -- 2.11.4.GIT