summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pall <mike>2015-04-28 20:28:16 +0200
committerMike Pall <mike>2015-04-28 20:28:16 +0200
commit11106aa83374c95f88679452e997229ecedefdcc (patch)
treebac4834ab59d2a211d475f5dc5ab9a3f17bf0aaf
parenta9fd68674483b2f886b925c2199e5f81c36c656a (diff)
downloadluajit2-11106aa83374c95f88679452e997229ecedefdcc.tar.gz
Fix stack check in narrowing optimization.
Thanks to Robert Nix.
-rw-r--r--src/lj_opt_narrow.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/lj_opt_narrow.c b/src/lj_opt_narrow.c
index b7bd3232..58b3763d 100644
--- a/src/lj_opt_narrow.c
+++ b/src/lj_opt_narrow.c
@@ -247,10 +247,16 @@ static void narrow_stripov_backprop(NarrowConv *nc, IRRef ref, int depth)
if (bp) {
ref = bp->val;
} else if (++depth < NARROW_MAX_BACKPROP && nc->sp < nc->maxsp) {
+ NarrowIns *savesp = nc->sp;
narrow_stripov_backprop(nc, ir->op1, depth);
- narrow_stripov_backprop(nc, ir->op2, depth);
- *nc->sp++ = NARROWINS(IRT(ir->o - IR_ADDOV + IR_ADD, IRT_INT), ref);
- return;
+ if (nc->sp < nc->maxsp) {
+ narrow_stripov_backprop(nc, ir->op2, depth);
+ if (nc->sp < nc->maxsp) {
+ *nc->sp++ = NARROWINS(IRT(ir->o - IR_ADDOV + IR_ADD, IRT_INT), ref);
+ return;
+ }
+ }
+ nc->sp = savesp; /* Path too deep, need to backtrack. */
}
}
*nc->sp++ = NARROWINS(NARROW_REF, ref);
@@ -263,6 +269,8 @@ static int narrow_conv_backprop(NarrowConv *nc, IRRef ref, int depth)
IRIns *ir = IR(ref);
IRRef cref;
+ if (nc->sp >= nc->maxsp) return 10; /* Path too deep. */
+
/* Check the easy cases first. */
if (ir->o == IR_CONV && (ir->op2 & IRCONV_SRCMASK) == IRT_INT) {
if ((nc->mode & IRCONV_CONVMASK) <= IRCONV_ANY)