Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH luajit v1] Fix BC_UCLO insertion for returns.
@ 2023-05-30 16:56 Sergey Bronnikov via Tarantool-patches
  2023-06-06 12:51 ` Sergey Kaplun via Tarantool-patches
  2023-07-20 18:37 ` Igor Munkin via Tarantool-patches
  0 siblings, 2 replies; 14+ messages in thread
From: Sergey Bronnikov via Tarantool-patches @ 2023-05-30 16:56 UTC (permalink / raw)
  To: tarantool-patches, Sergey Kaplun, Maxim Kokryashkin

From: Sergey Bronnikov <sergeyb@tarantool.org>

Contributed by XmiliaH.

(cherry-picked from commit 93a65d3cc263aef2d2feb3d7ff2206aca3bee17e)

After emitting bytecode instruction BC_FNEW fixup is not required,
because FuncState will set a flag PROTO_CHILD that will trigger emitting
a pair of instructions BC_UCLO and BC_RET (see <src/lj_parse.c:2355>)
and BC_RET will close all upvalues from base equal to 0.

Sergey Bronnikov:
* added the description and the test for the problem

Signed-off-by: Sergey Bronnikov <sergeyb@tarantool.org>
Co-authored-by: Sergey Kaplun <skaplun@tarantool.org>
---
Branch: https://github.com/tarantool/luajit/tree/ligurio/gh-819-fix-missing-uclo
PR: https://github.com/tarantool/tarantool/pull/8689

 src/lj_parse.c                                |  2 +-
 .../lj-819-fix-missing-uclo.test.lua          | 27 +++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 test/tarantool-tests/lj-819-fix-missing-uclo.test.lua

diff --git a/src/lj_parse.c b/src/lj_parse.c
index af0dc53f..343fa797 100644
--- a/src/lj_parse.c
+++ b/src/lj_parse.c
@@ -1546,7 +1546,7 @@ static void fs_fixup_ret(FuncState *fs)
 	/* Replace with UCLO plus branch. */
 	fs->bcbase[pc].ins = BCINS_AD(BC_UCLO, 0, offset);
 	break;
-      case BC_UCLO:
+      case BC_FNEW:
 	return;  /* We're done. */
       default:
 	break;
diff --git a/test/tarantool-tests/lj-819-fix-missing-uclo.test.lua b/test/tarantool-tests/lj-819-fix-missing-uclo.test.lua
new file mode 100644
index 00000000..b3f1f78a
--- /dev/null
+++ b/test/tarantool-tests/lj-819-fix-missing-uclo.test.lua
@@ -0,0 +1,27 @@
+local tap = require('tap')
+local test = tap.test('lj-819-fix-missing-uclo')
+
+test:plan(1)
+
+local function missing_uclo()
+  while true do -- luacheck: ignore
+    if false then
+      break
+    end
+    local f
+    while true do
+      if f then
+        return f
+      end
+      f = function()
+        return f
+      end
+    end
+  end
+end
+
+local f = missing_uclo()
+local res = f()
+test:ok(type(res) == 'function', 'type of returned value is correct')
+
+os.exit(test:check() and 0 or 1)
-- 
2.34.1


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2023-07-20 18:48 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-30 16:56 [Tarantool-patches] [PATCH luajit v1] Fix BC_UCLO insertion for returns Sergey Bronnikov via Tarantool-patches
2023-06-06 12:51 ` Sergey Kaplun via Tarantool-patches
2023-06-07 11:35   ` Maxim Kokryashkin via Tarantool-patches
2023-07-06  9:43     ` Sergey Bronnikov via Tarantool-patches
2023-07-06 11:31       ` Maxim Kokryashkin via Tarantool-patches
2023-07-06 13:45         ` Sergey Bronnikov via Tarantool-patches
2023-07-06 21:12           ` Maxim Kokryashkin via Tarantool-patches
2023-07-06  9:40   ` Sergey Bronnikov via Tarantool-patches
2023-07-09 13:15     ` Sergey Kaplun via Tarantool-patches
2023-07-10 14:53       ` Sergey Bronnikov via Tarantool-patches
2023-07-13  7:57         ` Sergey Kaplun via Tarantool-patches
2023-07-13  9:55           ` Sergey Bronnikov via Tarantool-patches
2023-07-13 10:25             ` Sergey Kaplun via Tarantool-patches
2023-07-20 18:37 ` Igor Munkin via Tarantool-patches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox