diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-03-30 14:58:14 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2021-03-30 14:58:49 +0200 |
commit | f0e2a6494b7553a89611bd7062459071119dae3c (patch) | |
tree | 28463d440507bec1c735faf07b381991b07224d8 /tests | |
parent | aa9621db401e881ffcdea03be272c94149484ccf (diff) |
tests: add missing test case for fixed switch codegen
Fixes: aa9621d ("compiler: rework switch statement code generation")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/03_bugs/11_switch_stack_mismatch | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/03_bugs/11_switch_stack_mismatch b/tests/03_bugs/11_switch_stack_mismatch new file mode 100644 index 0000000..cc3b41a --- /dev/null +++ b/tests/03_bugs/11_switch_stack_mismatch @@ -0,0 +1,39 @@ +When jumping into a case following prior cases declaring local variables, +the preceding local variable declarations were skipped, leading to an +unexpected stack layout which caused local variables to carry wrong +values at run time and eventual segmentation faults when attempting to +unwind the stack on leaving the lexical switch scope. + +-- Expect stdout -- +Matching 1: + - 1: [ null, null, 3, 4 ] + - 2: [ null, null, 3, 4, 5, 6 ] +Matching 2: + - 2: [ null, null, null, null, 5, 6 ] +Matching 3: + - default: [ 1, 2 ] + - 1: [ 1, 2, 3, 4 ] + - 2: [ 1, 2, 3, 4, 5, 6 ] +-- End -- + +-- Testcase -- +{% + for (let n in [1, 2, 3]) { + printf("Matching %d:\n", n); + + switch (n) { + default: + let x = 1, y = 2; + print(" - default: ", [x, y], "\n"); + + case 1: + let a = 3, b = 4; + print(" - 1: ", [x, y, a, b], "\n"); + + case 2: + let c = 5, d = 6; + print(" - 2: ", [x, y, a, b, c, d], "\n"); + } + } +%} +-- End -- |