UndertaleModTool icon indicating copy to clipboard operation
UndertaleModTool copied to clipboard

decompiler regression with GML SWITCH instruction

Open themabus opened this issue 2 years ago • 2 comments

Describe the bug

bitwise operation in Switch statement causes decompiler exception. happens in 674c5d8 and 0.4.0.4, was fine in 0.3.5.8

switch(x>>y) {
    case 0: x=1; break;
    case 1: x=2; break;
    case 2: x=3; break;
    default: x=10;
}
/* EXCEPTION!
   System.InvalidOperationException: The stack got misaligned? Error 2: Attempted to duplicate 16 bytes, only found 8
   at UndertaleModLib.Decompiler.Decompiler.DecompileFromBlock(DecompileContext context, Dictionary`2 blocks, Block block, List`1 tempvars, Stack`1 workQueue) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 2052
   at UndertaleModLib.Decompiler.Decompiler.DecompileFromBlock(DecompileContext context, Dictionary`2 blocks, Block block) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 2618
   at UndertaleModLib.Decompiler.Decompiler.Decompile(UndertaleCode code, GlobalDecompileContext globalContext) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 3769
   at UndertaleModTool.UndertaleCodeEditor.<>c__DisplayClass31_1.<DecompileCode>b__1() in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModTool\Editors\UndertaleCodeEditor.xaml.cs:line 456
*/

increment operation in Switch statement causes different kind of decompiler exception. happens in 674c5d8 and 0.4.0.4, was fine in 0.3.5.8

switch(x++) {
    case 0: x=1; break;
    case 1: x=10; break;
    case 2: x=100; break;
    default: x=0;
}
/* EXCEPTION!
   System.InvalidOperationException: Stack empty.
   at System.Collections.Generic.Stack`1.ThrowForEmptyStack()
   at System.Collections.Generic.Stack`1.Pop()
   at UndertaleModLib.Decompiler.Decompiler.DecompileFromBlock(DecompileContext context, Dictionary`2 blocks, Block block, List`1 tempvars, Stack`1 workQueue) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 2031
   at UndertaleModLib.Decompiler.Decompiler.DecompileFromBlock(DecompileContext context, Dictionary`2 blocks, Block block) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 2618
   at UndertaleModLib.Decompiler.Decompiler.Decompile(UndertaleCode code, GlobalDecompileContext globalContext) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 3769
   at UndertaleModTool.UndertaleCodeEditor.<>c__DisplayClass31_1.<DecompileCode>b__1() in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModTool\Editors\UndertaleCodeEditor.xaml.cs:line 456
*/

Reproducing steps

decompile script0/script1 from attached data.win bug_stack.zip

Setup Details

674c5d8 GMS 1.4.9999 Win10 x64

themabus avatar Jul 26 '22 16:07 themabus

switch (x > 0) {
    case 0:
        y++;
    break;
}

like above - this can be decompiled on v0.3.0 - v0.3.5.8, but not on v0.4.0.4 or BleedingEdge:

/* EXCEPTION!
   System.NotImplementedException: Unknown size for data type Boolean
   at UndertaleModLib.Decompiler.Decompiler.GetTypeSize(DataType type) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 1919
   at UndertaleModLib.Decompiler.Decompiler.DecompileFromBlock(DecompileContext context, Dictionary`2 blocks, Block block, List`1 tempvars, Stack`1 workQueue) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 2028
   at UndertaleModLib.Decompiler.Decompiler.DecompileFromBlock(DecompileContext context, Dictionary`2 blocks, Block block) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 2618
   at UndertaleModLib.Decompiler.Decompiler.Decompile(UndertaleCode code, GlobalDecompileContext globalContext) in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModLib\Decompiler\Decompiler.cs:line 3769
   at UndertaleModTool.UndertaleCodeEditor.<>c__DisplayClass31_1.<DecompileCode>b__1() in D:\a\UndertaleModTool\UndertaleModTool\UndertaleModTool\Editors\UndertaleCodeEditor.xaml.cs:line 456
*/

themabus avatar Aug 09 '22 15:08 themabus

i hope this gets fixed sometime soon

Reycko avatar Apr 28 '23 13:04 Reycko