diff options
author | Mike Pall <mike> | 2024-07-04 00:13:58 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2024-07-04 00:13:58 +0200 |
commit | 510f88d468b8a6d6feb02890417a7261073bcd87 (patch) | |
tree | a05cbbb64fc13273884de515287b01cdfacb3a66 | |
parent | 444c8ff19a39248307a7037354d6d259cc0e5efc (diff) | |
download | luajit-510f88d468b8a6d6feb02890417a7261073bcd87.tar.gz luajit-510f88d468b8a6d6feb02890417a7261073bcd87.tar.bz2 luajit-510f88d468b8a6d6feb02890417a7261073bcd87.zip |
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
-rw-r--r-- | src/lj_parse.c | 4 |
1 files changed, 4 insertions, 0 deletions
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) | |||
2339 | BCReg nret = expr_list(ls, &e); | 2339 | BCReg nret = expr_list(ls, &e); |
2340 | if (nret == 1) { /* Return one result. */ | 2340 | if (nret == 1) { /* Return one result. */ |
2341 | if (e.k == VCALL) { /* Check for tail call. */ | 2341 | if (e.k == VCALL) { /* Check for tail call. */ |
2342 | #ifdef LUAJIT_DISABLE_TAILCALL | ||
2343 | goto notailcall; | ||
2344 | #else | ||
2342 | BCIns *ip = bcptr(fs, &e); | 2345 | BCIns *ip = bcptr(fs, &e); |
2343 | /* It doesn't pay off to add BC_VARGT just for 'return ...'. */ | 2346 | /* It doesn't pay off to add BC_VARGT just for 'return ...'. */ |
2344 | if (bc_op(*ip) == BC_VARG) goto notailcall; | 2347 | if (bc_op(*ip) == BC_VARG) goto notailcall; |
2345 | fs->pc--; | 2348 | fs->pc--; |
2346 | ins = BCINS_AD(bc_op(*ip)-BC_CALL+BC_CALLT, bc_a(*ip), bc_c(*ip)); | 2349 | ins = BCINS_AD(bc_op(*ip)-BC_CALL+BC_CALLT, bc_a(*ip), bc_c(*ip)); |
2350 | #endif | ||
2347 | } else { /* Can return the result from any register. */ | 2351 | } else { /* Can return the result from any register. */ |
2348 | ins = BCINS_AD(BC_RET1, expr_toanyreg(fs, &e), 2); | 2352 | ins = BCINS_AD(BC_RET1, expr_toanyreg(fs, &e), 2); |
2349 | } | 2353 | } |