summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjgravelle-google <jgravelle@google.com>2016-10-27 10:56:11 -0700
committerGitHub <noreply@github.com>2016-10-27 10:56:11 -0700
commit82639c7c658f4335850fe290f4cd6b34f3fb91f5 (patch)
treee6777143ff8a5c0cdb63f276d33457ca28a9fe3f
parentafad1ee305719cf2a34b6dcccff72b07e1a5e34d (diff)
downloadbinaryen-82639c7c658f4335850fe290f4cd6b34f3fb91f5.tar.gz
binaryen-82639c7c658f4335850fe290f4cd6b34f3fb91f5.tar.bz2
binaryen-82639c7c658f4335850fe290f4cd6b34f3fb91f5.zip
Set the type of the implicit blocks we use for a loop body in s2wasm (#810)
Loops are modeled in Binaryen IR as having a Block as a body. The block is added to module walkers and validated like a normal block. In s2wasm when we add the blocks, we need to make sure that the type of the loop body matches the type of the loop itself, or we run into issues.
-rw-r--r--src/s2wasm.h1
-rw-r--r--test/dot_s/return.s12
-rw-r--r--test/dot_s/return.wast9
3 files changed, 22 insertions, 0 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h
index 1e52cfbce..c5b502c6d 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -1129,6 +1129,7 @@ class S2WasmBuilder {
curr->name = getNextLabel();
auto implicitBlock = allocator->alloc<Block>();
curr->body = implicitBlock;
+ implicitBlock->type = loopType;
bstack.push_back(curr);
} else if (match("end_loop")) {
auto* loop = bstack.back()->cast<Loop>();
diff --git a/test/dot_s/return.s b/test/dot_s/return.s
index 5a0bded5a..9ceaabaf5 100644
--- a/test/dot_s/return.s
+++ b/test/dot_s/return.s
@@ -15,3 +15,15 @@ return_void:
.Lfunc_end0:
.size return_void, .Lfunc_end0-return_void
+ .type fallthrough_return_nested_loop_i32,@function
+fallthrough_return_nested_loop_i32:
+ .result i32
+ loop i32
+ loop i32
+ i32.const $push0=, 1
+ return $pop0
+ end_loop
+ end_loop
+ .endfunc
+.Lfunc_end0:
+ .size fallthrough_return_nested_loop_i32, .Lfunc_end0-fallthrough_return_nested_loop_i32
diff --git a/test/dot_s/return.wast b/test/dot_s/return.wast
index 896e99357..ee7bc2ed2 100644
--- a/test/dot_s/return.wast
+++ b/test/dot_s/return.wast
@@ -8,5 +8,14 @@
)
(func $return_void
)
+ (func $fallthrough_return_nested_loop_i32 (result i32)
+ (loop $label$0 i32
+ (loop $label$1 i32
+ (return
+ (i32.const 1)
+ )
+ )
+ )
+ )
)
;; METADATA: { "asmConsts": {},"staticBump": 12, "initializers": [] }