optimized bound checking
This commit is contained in:
parent
264dbcfed2
commit
17cbb388d3
1 changed files with 14 additions and 9 deletions
21
tcc.c
21
tcc.c
|
|
@ -286,6 +286,8 @@ struct TCCState {
|
||||||
char/short stored in integer registers) */
|
char/short stored in integer registers) */
|
||||||
#define VT_MUSTBOUND 0x0800 /* bound checking must be done before
|
#define VT_MUSTBOUND 0x0800 /* bound checking must be done before
|
||||||
dereferencing value */
|
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_BYTE 0x1000 /* lvalue is a byte */
|
||||||
#define VT_LVAL_SHORT 0x2000 /* lvalue is a short */
|
#define VT_LVAL_SHORT 0x2000 /* lvalue is a short */
|
||||||
#define VT_LVAL_UNSIGNED 0x4000 /* lvalue is unsigned */
|
#define VT_LVAL_UNSIGNED 0x4000 /* lvalue is unsigned */
|
||||||
|
|
@ -2660,12 +2662,16 @@ void gbound(void)
|
||||||
vtop->r &= ~VT_MUSTBOUND;
|
vtop->r &= ~VT_MUSTBOUND;
|
||||||
/* if lvalue, then use checking code before dereferencing */
|
/* if lvalue, then use checking code before dereferencing */
|
||||||
if (vtop->r & VT_LVAL) {
|
if (vtop->r & VT_LVAL) {
|
||||||
lval_type = vtop->r & (VT_LVAL_TYPE | VT_LVAL);
|
/* if not VT_BOUNDED value, then make one */
|
||||||
gaddrof();
|
if (!(vtop->r & VT_BOUNDED)) {
|
||||||
vpushi(0);
|
lval_type = vtop->r & (VT_LVAL_TYPE | VT_LVAL);
|
||||||
gen_bounded_ptr_add1();
|
gaddrof();
|
||||||
gen_bounded_ptr_add2(1);
|
vpushi(0);
|
||||||
vtop->r |= lval_type;
|
gen_bounded_ptr_add();
|
||||||
|
vtop->r |= lval_type;
|
||||||
|
}
|
||||||
|
/* then check for dereferencing */
|
||||||
|
gen_bounded_ptr_deref();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -3365,8 +3371,7 @@ void gen_op(int op)
|
||||||
vswap();
|
vswap();
|
||||||
gen_op('-');
|
gen_op('-');
|
||||||
}
|
}
|
||||||
gen_bounded_ptr_add1();
|
gen_bounded_ptr_add();
|
||||||
gen_bounded_ptr_add2(0);
|
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue