diff options
author | Mike Pall <mike> | 2015-04-28 20:28:16 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2015-04-28 20:28:16 +0200 |
commit | 11106aa83374c95f88679452e997229ecedefdcc (patch) | |
tree | bac4834ab59d2a211d475f5dc5ab9a3f17bf0aaf | |
parent | a9fd68674483b2f886b925c2199e5f81c36c656a (diff) | |
download | luajit-11106aa83374c95f88679452e997229ecedefdcc.tar.gz luajit-11106aa83374c95f88679452e997229ecedefdcc.tar.bz2 luajit-11106aa83374c95f88679452e997229ecedefdcc.zip |
Fix stack check in narrowing optimization.
Thanks to Robert Nix.
-rw-r--r-- | src/lj_opt_narrow.c | 14 |
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) | |||
247 | if (bp) { | 247 | if (bp) { |
248 | ref = bp->val; | 248 | ref = bp->val; |
249 | } else if (++depth < NARROW_MAX_BACKPROP && nc->sp < nc->maxsp) { | 249 | } else if (++depth < NARROW_MAX_BACKPROP && nc->sp < nc->maxsp) { |
250 | NarrowIns *savesp = nc->sp; | ||
250 | narrow_stripov_backprop(nc, ir->op1, depth); | 251 | narrow_stripov_backprop(nc, ir->op1, depth); |
251 | narrow_stripov_backprop(nc, ir->op2, depth); | 252 | if (nc->sp < nc->maxsp) { |
252 | *nc->sp++ = NARROWINS(IRT(ir->o - IR_ADDOV + IR_ADD, IRT_INT), ref); | 253 | narrow_stripov_backprop(nc, ir->op2, depth); |
253 | return; | 254 | if (nc->sp < nc->maxsp) { |
255 | *nc->sp++ = NARROWINS(IRT(ir->o - IR_ADDOV + IR_ADD, IRT_INT), ref); | ||
256 | return; | ||
257 | } | ||
258 | } | ||
259 | nc->sp = savesp; /* Path too deep, need to backtrack. */ | ||
254 | } | 260 | } |
255 | } | 261 | } |
256 | *nc->sp++ = NARROWINS(NARROW_REF, ref); | 262 | *nc->sp++ = NARROWINS(NARROW_REF, ref); |
@@ -263,6 +269,8 @@ static int narrow_conv_backprop(NarrowConv *nc, IRRef ref, int depth) | |||
263 | IRIns *ir = IR(ref); | 269 | IRIns *ir = IR(ref); |
264 | IRRef cref; | 270 | IRRef cref; |
265 | 271 | ||
272 | if (nc->sp >= nc->maxsp) return 10; /* Path too deep. */ | ||
273 | |||
266 | /* Check the easy cases first. */ | 274 | /* Check the easy cases first. */ |
267 | if (ir->o == IR_CONV && (ir->op2 & IRCONV_SRCMASK) == IRT_INT) { | 275 | if (ir->o == IR_CONV && (ir->op2 & IRCONV_SRCMASK) == IRT_INT) { |
268 | if ((nc->mode & IRCONV_CONVMASK) <= IRCONV_ANY) | 276 | if ((nc->mode & IRCONV_CONVMASK) <= IRCONV_ANY) |