diff options
-rw-r--r-- | src/wasm-s-parser.h | 12 | ||||
-rw-r--r-- | test/unit.2asm.js | 10 | ||||
-rw-r--r-- | test/unit.wast | 7 |
3 files changed, 23 insertions, 6 deletions
diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index f204d933a..b36740ebd 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -317,6 +317,7 @@ private: localIndex = 0; otherIndex = 0; std::vector<NameType> typeParams; // we may have both params and a type. store the type info here + Block* autoBlock = nullptr; // we may need to add a block for the very top level for (;i < s.size(); i++) { Element& curr = *s[i]; IString id = curr[0]->str(); @@ -368,13 +369,12 @@ private: if (!func->body) { func->body = ex; } else { - auto block = func->body->dyn_cast<Block>(); - if (!block) { - block = allocator.alloc<Block>(); - block->list.push_back(func->body); - func->body = block; + if (!autoBlock) { + autoBlock = allocator.alloc<Block>(); + autoBlock->list.push_back(func->body); + func->body = autoBlock; } - block->list.push_back(ex); + autoBlock->list.push_back(ex); } } } diff --git a/test/unit.2asm.js b/test/unit.2asm.js index 953437f63..ca62fb0d9 100644 --- a/test/unit.2asm.js +++ b/test/unit.2asm.js @@ -241,6 +241,16 @@ function asmFunc(global, env, buffer) { } + function block_and_after() { + var wasm2asm_i32$0 = 0; + waka : { + 1; + break waka; + } + wasm2asm_i32$0 = 0; + return wasm2asm_i32$0 | 0; + } + var FUNCTION_TABLE_d = [importedDoubles, importedDoubles, importedDoubles, importedDoubles, importedDoubles, importedDoubles, importedDoubles, importedDoubles, importedDoubles, importedDoubles, importedDoubles, importedDoubles, importedDoubles, importedDoubles, importedDoubles, importedDoubles]; var FUNCTION_TABLE_v = [z, big_negative, z, z, w, w, z, w, z, z, z, z, z, z, z, z]; var FUNCTION_TABLE_vf = [cneg, cneg, cneg, cneg, cneg, cneg, cneg, cneg, cneg, cneg, cneg, cneg, cneg, cneg, cneg, cneg]; diff --git a/test/unit.wast b/test/unit.wast index 4311a2a33..55c9e9fa1 100644 --- a/test/unit.wast +++ b/test/unit.wast @@ -378,4 +378,11 @@ (func $w (nop) ) + (func $block_and_after (result i32) + (block $waka + (i32.const 1) + (br $waka) + ) + (i32.const 0) + ) ) |