1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-26 00:10:27 +00:00

Prevent bytecode optimization from remove mk* instructions.

These instructions read from the stack, and therefor have side effects.
Removing them without clearing the stack results in broken bytecode.
This commit is contained in:
Calvin Rose 2023-11-22 08:18:23 -06:00
parent 16f409c6a9
commit a9176a77e6
2 changed files with 10 additions and 0 deletions

View File

@ -226,6 +226,7 @@ void janet_bytecode_movopt(JanetFuncDef *def) {
case JOP_LOAD_TRUE: case JOP_LOAD_TRUE:
case JOP_LOAD_FALSE: case JOP_LOAD_FALSE:
case JOP_LOAD_SELF: case JOP_LOAD_SELF:
break;
case JOP_MAKE_ARRAY: case JOP_MAKE_ARRAY:
case JOP_MAKE_BUFFER: case JOP_MAKE_BUFFER:
case JOP_MAKE_STRING: case JOP_MAKE_STRING:
@ -233,6 +234,8 @@ void janet_bytecode_movopt(JanetFuncDef *def) {
case JOP_MAKE_TABLE: case JOP_MAKE_TABLE:
case JOP_MAKE_TUPLE: case JOP_MAKE_TUPLE:
case JOP_MAKE_BRACKET_TUPLE: case JOP_MAKE_BRACKET_TUPLE:
/* Reads from the stack, don't remove */
janetc_regalloc_touch(&ra, DD);
break; break;
/* Read A */ /* Read A */

View File

@ -961,4 +961,11 @@
# (pp (disasm case-2)) # (pp (disasm case-2))
# (pp (disasm case-3)) # (pp (disasm case-3))
# Regression #1330
(defn regress-1330 [&]
(def a [1 2 3])
(def b [;a])
(identity a))
(assert (= [1 2 3] (regress-1330)) "regression 1330")
(end-suite) (end-suite)