Fix cppia JIT "Bad move target" on untyped register moves - #1369
Open
MeguminBOT wants to merge 1 commit into
Open
Fix cppia JIT "Bad move target" on untyped register moves#1369MeguminBOT wants to merge 1 commit into
MeguminBOT wants to merge 1 commit into
Conversation
CppiaCompiler::convert moves between two untyped registers in three places. getCommonType(jtAny, jtAny) returns jtAny, which move() rejects. The cppia test suite covers it, run with -jit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Remake of #1366
The problem
With the JIT on, a cppia module containing an ordinary integer expression fails to load:
The failure is at module boot, because JIT compilation runs over the whole module there, so one
expression takes the entire module down. cppia with jit off runs the same code correctly.
Why
CppiaCompiler::convertmoves between two untyped registers in three places, for example whenconverting an
Intto aString:Neither side is given a width. When both operands are untyped,
getCommonType(jtAny, jtAny)returnsjtAny, whichmove()rejects withsetError("Bad move target"). That is thrown, caught inCppiaModule, and re-raised as the load error above.It needs both conditions at once, which is why it is easy to miss: the source has to be in
R1anduntyped. An expression like
"" + (a * b)reaches the branch but with a typed source, and"" + ints[0]has an untyped source but does not reach the branch.The fix
In
src/hx/cppia/CppiaCompiler.cpp, give both sides a width:Test
test/cppiacovers it.ClientUntypedMoveinClient.hxsubtracts one array element from anotherinto a string, and
testUntypedRegisterMoveincases/TestCommon.hxchecks the answer.The
-jitmatters, andRunTests.hxalready runs the suite both ways.Without the fix, the
-jitrun fails atsetupClass failed: Bad move targetand exits 1, since themodule never loads. The same build without
-jitreportsALL TESTS OK.Reproducing by hand
Built with
haxe -m Script --cppia script.cppiaand loaded from a host built with-D scriptable --dce no, callingcpp.cppia.Host.enableJit(true)beforecpp.cppia.Module.fromData(bytes).boot().Error : Bad move targetat boot11