From 510f88d468b8a6d6feb02890417a7261073bcd87 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Thu, 4 Jul 2024 00:13:58 +0200 Subject: [PATCH] Add build flag LUAJIT_DISABLE_TAILCALL to disable tailcall generation. Only use this for debugging purposes. NEVER set it for regular builds or distro builds! In Lua, tailcalls are a language guarantee. Suggested by Steve Vermeulen. #1220 --- src/lj_parse.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lj_parse.c b/src/lj_parse.c index db3ce8e7..4fdd4c65 100644 --- a/src/lj_parse.c +++ b/src/lj_parse.c @@ -2339,11 +2339,15 @@ static void parse_return(LexState *ls) BCReg nret = expr_list(ls, &e); if (nret == 1) { /* Return one result. */ if (e.k == VCALL) { /* Check for tail call. */ +#ifdef LUAJIT_DISABLE_TAILCALL + goto notailcall; +#else BCIns *ip = bcptr(fs, &e); /* It doesn't pay off to add BC_VARGT just for 'return ...'. */ if (bc_op(*ip) == BC_VARG) goto notailcall; fs->pc--; ins = BCINS_AD(bc_op(*ip)-BC_CALL+BC_CALLT, bc_a(*ip), bc_c(*ip)); +#endif } else { /* Can return the result from any register. */ ins = BCINS_AD(BC_RET1, expr_toanyreg(fs, &e), 2); }