Skip to content

Fix cppia JIT "Bad move target" on untyped register moves - #1366

Open
MeguminBOT wants to merge 1 commit into
HaxeFoundation:masterfrom
MeguminBOT:fix-cppia-jit-untyped-register-move
Open

Fix cppia JIT "Bad move target" on untyped register moves#1366
MeguminBOT wants to merge 1 commit into
HaxeFoundation:masterfrom
MeguminBOT:fix-cppia-jit-untyped-register-move

Conversation

@MeguminBOT

Copy link
Copy Markdown

Any binary subtraction inside a ternary that is converted to String or object triggers it.
Multiplication, division, unary minus and addition are unaffected, as is hoisting the subtraction into a local first.

CppiaCompiler::convert moved between two registers without giving either a type in three places.
move() decides what to emit from getCommonType(), and getCommonType(jtAny, jtAny) returns jtAny, which the
switch answers with setError("Bad move target").

All three sites are guarded by inSrc.uses(SLJIT_R1) or inSrc==sJitTemp1, so they are only reached when the source value happens to live in R1.
OpAdd::genCode leaves its int result in sJitTemp0 and misses the guard, while OpSub::genCode uses sJitTemp1 and hits it, which is why addition compiles and subtraction does not.

Reproducable steps

class Repro {
    static function f(a:Int, b:Int, flag:Bool):String {
        return "x" + (flag ? 0 : a - b);
    }
    public static function main() Sys.println(f(5, 3, false));
}

Run

haxe -main Repro -cppia repro.cppia
haxe -main cpp.cppia.Host -D scriptable -dce no -cpp host
host/Host.exe -jit repro.cppia    Error : Bad move target
host/Host.exe      repro.cppia    x2

CppiaCompiler::convert moves between two untyped registers in three places.
getCommonType(jtAny, jtAny) returns jtAny, which move() rejects.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant