From 217ed8c23335973788a9bfbdde484ef457d1fa76 Mon Sep 17 00:00:00 2001 From: Peter Cawley Date: Sat, 2 Apr 2016 18:18:00 +0100 Subject: [PATCH] Add extra guard when recording `select(x, ...)` with off-trace varargs For example, the following previously failed when it got jitted: local select = select local exptyp = "number" local function f(...) for i = 1, 100 do assert(type((select('#', ...))) == exptyp) if i == 75 then select = function() return "" end exptyp = "string" end end end f(1) --- src/lj_record.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lj_record.c b/src/lj_record.c index 90f53af3..d6dd73bc 100644 --- a/src/lj_record.c +++ b/src/lj_record.c @@ -1693,8 +1693,11 @@ static int select_detect(jit_State *J) BCIns ins = J->pc[1]; if (bc_op(ins) == BC_CALLM && bc_b(ins) == 2 && bc_c(ins) == 1) { cTValue *func = &J->L->base[bc_a(ins)]; - if (tvisfunc(func) && funcV(func)->c.ffid == FF_select) + if (tvisfunc(func) && funcV(func)->c.ffid == FF_select) { + TRef kfunc = lj_ir_kfunc(J, funcV(func)); + emitir(IRTG(IR_EQ, IRT_FUNC), getslot(J, bc_a(ins)), kfunc); return 1; + } } return 0; }