summaryrefslogtreecommitdiffhomepage
path: root/tests/custom/04_bugs/10_break_stack_mismatch
diff options
context:
space:
mode:
Diffstat (limited to 'tests/custom/04_bugs/10_break_stack_mismatch')
-rw-r--r--tests/custom/04_bugs/10_break_stack_mismatch38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/custom/04_bugs/10_break_stack_mismatch b/tests/custom/04_bugs/10_break_stack_mismatch
new file mode 100644
index 0000000..ae16dac
--- /dev/null
+++ b/tests/custom/04_bugs/10_break_stack_mismatch
@@ -0,0 +1,38 @@
+When emitting jump instructions for breaking out of for-loops, the compiler
+incorrectly set the jump target before the pop instruction clearing the
+intermediate loop variables. Since the break instruction itself already
+compiles to a series of pop instructions reverting the stack to it's the
+pre-loop state, intermediate values got popped twice, leading to a stack
+layout mismatch between compiler and VM, resulting in wrong local variable
+values or segmentation faults at runtime.
+
+-- Testcase --
+{%
+ let x = 1;
+
+ for (let y in [2])
+ break;
+
+ print(x, "\n");
+%}
+-- End --
+
+-- Expect stdout --
+1
+-- End --
+
+
+-- Testcase --
+{%
+ let x = 1;
+
+ for (let y = 0; y < 1; y++)
+ break;
+
+ print(x, "\n");
+%}
+-- End --
+
+-- Expect stdout --
+1
+-- End --