• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/ucode/tests/custom/99_bugs/10_break_stack_mismatch

  1 When emitting jump instructions for breaking out of for-loops, the compiler
  2 incorrectly set the jump target before the pop instruction clearing the
  3 intermediate loop variables. Since the break instruction itself already
  4 compiles to a series of pop instructions reverting the stack to it's the
  5 pre-loop state, intermediate values got popped twice, leading to a stack
  6 layout mismatch between compiler and VM, resulting in wrong local variable
  7 values or segmentation faults at runtime.
  8 
  9 -- Testcase --
 10 {%
 11         let x = 1;
 12 
 13         for (let y in [2])
 14                 break;
 15 
 16         let z = 3;
 17 
 18         print([ x, z ], "\n");
 19 %}
 20 -- End --
 21 
 22 -- Expect stdout --
 23 [ 1, 3 ]
 24 -- End --
 25 
 26 
 27 -- Testcase --
 28 {%
 29         let x = 1;
 30 
 31         for (let y = 0; y < 1; y++)
 32                 break;
 33 
 34         let z = 3;
 35 
 36         print([ x, z ], "\n");
 37 %}
 38 -- End --
 39 
 40 -- Expect stdout --
 41 [ 1, 3 ]
 42 -- End --

This page was automatically generated by LXR 0.3.1.  •  OpenWrt