diff options
-rw-r--r-- | src/asm2wasm.h | 3 | ||||
-rw-r--r-- | test/unit.asm.js | 27 | ||||
-rw-r--r-- | test/unit.fromasm | 37 | ||||
-rw-r--r-- | test/unit.fromasm.imprecise | 37 |
4 files changed, 103 insertions, 1 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h index c994d0ef2..4c37b7705 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -419,8 +419,9 @@ private: return nullptr; } + // ensure a nameless block Block* blockify(Expression* expression) { - if (expression->is<Block>()) return expression->dyn_cast<Block>(); + if (expression->is<Block>() && !expression->cast<Block>()->name.is()) return expression->dyn_cast<Block>(); auto ret = allocator.alloc<Block>(); ret->list.push_back(expression); ret->finalize(); diff --git a/test/unit.asm.js b/test/unit.asm.js index c600f714d..5bb84bdcd 100644 --- a/test/unit.asm.js +++ b/test/unit.asm.js @@ -55,6 +55,7 @@ function asm() { } function switcher(x) { x = x | 0; + var waka = 0; switch (x | 0) { case 1: return 1; case 2: return 2; @@ -79,6 +80,32 @@ function asm() { break; } } + + L1 : while (1) { + L3 : while (1) switch (x) { + case -1: + { + break L1; + break; + } + case 116: + { + waka = 1; + break; + } + case 110: + { + break L3; + break; + } + default: + { + break L1; + } + } + h(120); + } + return 0; } function blocker() { diff --git a/test/unit.fromasm b/test/unit.fromasm index e00c6b43b..3db25c78b 100644 --- a/test/unit.fromasm +++ b/test/unit.fromasm @@ -177,6 +177,7 @@ ) ) (func $switcher (param $x i32) (result i32) + (local $waka i32) (block $switch-default$3 (block $switch-case$2 (block $switch-case$1 @@ -243,6 +244,42 @@ (br $label$break$Lout) ) ) + (loop $label$break$L1 $label$continue$L1 + (loop $label$break$L3 $label$continue$L3 + (block $switch$17 + (block $switch-default$21 + (block $switch-default$21 + (block $switch-case$20 + (block $switch-case$19 + (block $switch-case$18 + (br_table $switch-case$18 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-case$20 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-case$19 $switch-default$21 + (i32.sub + (get_local $x) + (i32.const -1) + ) + ) + ) + (br $label$break$L1) + (br $switch$17) + ) + (set_local $waka + (i32.const 1) + ) + (br $switch$17) + ) + (br $label$break$L3) + (br $switch$17) + ) + (br $label$break$L1) + ) + ) + (br $label$continue$L3) + ) + (call_import $h + (i32.const 120) + ) + (br $label$continue$L1) + ) (return (i32.const 0) ) diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise index 9bfa1789c..ef9ccaa5d 100644 --- a/test/unit.fromasm.imprecise +++ b/test/unit.fromasm.imprecise @@ -173,6 +173,7 @@ ) ) (func $switcher (param $x i32) (result i32) + (local $waka i32) (block $switch-default$3 (block $switch-case$2 (block $switch-case$1 @@ -239,6 +240,42 @@ (br $label$break$Lout) ) ) + (loop $label$break$L1 $label$continue$L1 + (loop $label$break$L3 $label$continue$L3 + (block $switch$17 + (block $switch-default$21 + (block $switch-default$21 + (block $switch-case$20 + (block $switch-case$19 + (block $switch-case$18 + (br_table $switch-case$18 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-case$20 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-default$21 $switch-case$19 $switch-default$21 + (i32.sub + (get_local $x) + (i32.const -1) + ) + ) + ) + (br $label$break$L1) + (br $switch$17) + ) + (set_local $waka + (i32.const 1) + ) + (br $switch$17) + ) + (br $label$break$L3) + (br $switch$17) + ) + (br $label$break$L1) + ) + ) + (br $label$continue$L3) + ) + (call_import $h + (i32.const 120) + ) + (br $label$continue$L1) + ) (return (i32.const 0) ) |