Fix rindex tail call recording #70
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi LuaVela team,
There are some problems with recording tail-called
rindex():CALLT(orCALLMT) recording,RETFinstruction will be emitted before them:Just to compare, this is IR with regular return (
RETFis placed after checks):This patch emits return value check before
RETFand later fixes guard type. Example above will looks like:lj_tab_rawrindex_jitresult (sinceJ->basewill be pointing to previous frame by the timeLJ_POST_FFSPECRETis applied). This is IR for the second test example (instead of rindex its argument"k1"is checked):lj_tab_rawrindex_jitcall will be completely purged out from assembled trace due to it, butNEandTVLOADstill be present and will check random registers.This patch fixes this case too:
J->pc - 1will point toHOTCNTbytecode instead ofCALL(M)duringLJ_POST_FFSPECRETfixup. This case covered by 3rd testcase.PS. Also looks like its safe to remove assert for
CALLTandCALLMT, since by the time ofLJ_POST_FFSPECRETexecution VM is already returned to lower frame and can't hitCALLTorCALLMT.I'm not absolutely sure about correctness of the patch, please help to figure it out.
Thanks in advance!