Skip to content
This repository has been archived by the owner on May 15, 2018. It is now read-only.

Fix edge case with many arguments #13

Merged
merged 6 commits into from
Mar 22, 2015
Merged

Fix edge case with many arguments #13

merged 6 commits into from
Mar 22, 2015

Conversation

SquidDev
Copy link
Member

There was an issue with code similar to this:

local function arg(a, b, ...)
    if a then error() end
    b = b + 1 -- Error occurs here
end

The issue lies in the code being a VarArgFunction, and so variables have to be extracted into slots. However the slot variable for b is never set as it doesn't think the argument is being used.

You can see from the block breakdown that block 5-6 has 2 previous blocks. As a result it didn't know which variable to use and so it never said that the argument was used.

proto 'EdgeCases_LuaCompiled$0'
    block 1-2  nxt: (3,5)
         0.p    1.p    2.p    3.p        1  [-]  TEST  0 0 0
         0.p    1.p    2.p    3.p        2  [4]  JMP  2  ; to 5
    block 3-4  prv: (2)  nxt: (5)
         0.p    1.p    2.p    3.2        3  [4]  GETGLOBAL  3 -1  ; "error"
         0.p    1.p    2.p    x.x        4  [4]  CALL  3 1 1
    block 5-6  prv: (4,2)
         0.p    1.4    2.p    x.x        5  [5]  ADD  1 1 -2  ; - 1
         0.p    1.4    2.p    x.x        6  [6]  RETURN  0 1

The fix checks that if all slots in previous blocks are the same then this slot must be equal to that one.

@SquidDev
Copy link
Member Author

This isn't ready to be merged as the fix will not address issues such as:

local function func(a, b, ...)
    if a then b = 0 end
    b = b + 1
end

Having read the code a bit more, most of this is already implemented within PhiVarInfo, however the PhiVarInfo is disposed as we assign it to the same variable.

SquidDev added a commit that referenced this pull request Mar 22, 2015
The final solution keeps a track of all `PhiVarInfo` instances and forcibly resolves those not already resolved.
@SquidDev SquidDev merged commit 0ab50ed into master Mar 22, 2015
@SquidDev
Copy link
Member Author

The fix forcibly resolves those PhiVarInfo instances not already resolved. PhiVarInfo instances will always bubble up their isreferenced settings.

@SquidDev SquidDev deleted the bugfix/luajc-manyargs branch March 22, 2015 17:39
SquidDev added a commit to SquidDev-CC/CCTweaks that referenced this pull request Mar 22, 2015
@SquidDev SquidDev added the bug label Mar 24, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant