changeset 489:4fa19d879ada

Fix issue with testset redirect to line 1 or 2 (5.4+)
author tehtmi
date Sat, 14 Jan 2023 15:38:48 -0800
parents 4c34e2d5119c
children 9e0eae01e185
files src/unluac/decompile/ControlFlowHandler.java src/unluac/test/TestFiles.java test/src/while08.lua
diffstat 3 files changed, 20 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/unluac/decompile/ControlFlowHandler.java	Wed Dec 14 15:24:42 2022 -0800
+++ b/src/unluac/decompile/ControlFlowHandler.java	Sat Jan 14 15:38:48 2023 -0800
@@ -180,6 +180,9 @@
   }
   
   private static int find_loadboolblock(State state, int target) {
+    if(target < 1) {
+      return -1;
+    }
     int loadboolblock = -1;
     Op op = state.code.op(target);
     if(op == Op.LOADBOOL) {
--- a/src/unluac/test/TestFiles.java	Wed Dec 14 15:24:42 2022 -0800
+++ b/src/unluac/test/TestFiles.java	Sat Jan 14 15:38:48 2023 -0800
@@ -43,6 +43,7 @@
     new TestFile("while05"),
     new TestFile("while06"),
     new TestFile("while07"),
+    new TestFile("while08"),
     new TestFile("repeat"),
     new TestFile("repeat02"),
     new TestFile("repeat03"),
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/src/while08.lua	Sat Jan 14 15:38:48 2023 -0800
@@ -0,0 +1,16 @@
+-- inner function to avoid varargprep in 5.4
+function f(x)
+  -- loopback at 1
+  while g1(x) do
+    -- testset redirected to loopback (only in 5.4+)
+    x = g2(x) and "a" or "b"
+  end
+end
+
+function f2(x)
+  local y
+  --loopback at 2
+  while g1(x) do
+    x = g2(x) and "a" or "b"
+  end
+end