diff options
author | Heejin Ahn <aheejin@gmail.com> | 2019-12-12 18:36:31 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-12 18:36:31 -0800 |
commit | 89d1cf92be0636a219ee6415eead387241963dcf (patch) | |
tree | ecd7c3541def138353ccf5e095b90a656070a3d5 /test/example | |
parent | 759c485a9f35bd859d43b86b02e1397a669fa469 (diff) | |
download | binaryen-89d1cf92be0636a219ee6415eead387241963dcf.tar.gz binaryen-89d1cf92be0636a219ee6415eead387241963dcf.tar.bz2 binaryen-89d1cf92be0636a219ee6415eead387241963dcf.zip |
Make local.tee's type its local's type (#2511)
According to the current spec, `local.tee`'s return type should be the
same as its local's type. (Discussions on whether we should change this
rule is going on in WebAssembly/reference-types#55, but here I will
assume this spec does not change. If this changes, we should change many
parts of Binaryen transformation anyway...)
But currently in Binaryen `local.tee`'s type is computed from its
value's type. This didn't make any difference in the MVP, but after we
have subtype relationship in #2451, this can become a problem. For
example:
```
(func $test (result funcref) (local $0 anyref)
(local.tee $0
(ref.func $test)
)
)
```
This shouldn't validate in the spec, but this will pass Binaryen
validation with the current `local.tee` implementation.
This makes `local.tee`'s type computed from the local's type, and makes
`LocalSet::makeTee` get a type parameter, to which we should pass the
its corresponding local's type. We don't embed the local type in the
class `LocalSet` because it may increase memory size.
This also fixes the type of `local.get` to be the local type where
`local.get` and `local.set` pair is created from `local.tee`.
Diffstat (limited to 'test/example')
-rw-r--r-- | test/example/c-api-kitchen-sink.c | 4 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.txt | 2 | ||||
-rw-r--r-- | test/example/c-api-relooper-unreachable-if.cpp | 9 |
3 files changed, 10 insertions, 5 deletions
diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c index b3419d184..6284cdd39 100644 --- a/test/example/c-api-kitchen-sink.c +++ b/test/example/c-api-kitchen-sink.c @@ -648,7 +648,9 @@ void test_core() { BinaryenTypeInt32())), BinaryenDrop(module, BinaryenLocalGet(module, 0, BinaryenTypeInt32())), BinaryenLocalSet(module, 0, makeInt32(module, 101)), - BinaryenDrop(module, BinaryenLocalTee(module, 0, makeInt32(module, 102))), + BinaryenDrop( + module, + BinaryenLocalTee(module, 0, makeInt32(module, 102), BinaryenTypeInt32())), BinaryenLoad(module, 4, 0, 0, 0, BinaryenTypeInt32(), makeInt32(module, 1)), BinaryenLoad(module, 2, 1, 2, 1, BinaryenTypeInt64(), makeInt32(module, 8)), BinaryenLoad( diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt index ca9061e63..a75fd7380 100644 --- a/test/example/c-api-kitchen-sink.txt +++ b/test/example/c-api-kitchen-sink.txt @@ -1604,7 +1604,7 @@ int main() { expressions[747] = BinaryenConst(the_module, BinaryenLiteralInt32(101)); expressions[748] = BinaryenLocalSet(the_module, 0, expressions[747]); expressions[749] = BinaryenConst(the_module, BinaryenLiteralInt32(102)); - expressions[750] = BinaryenLocalTee(the_module, 0, expressions[749]); + expressions[750] = BinaryenLocalTee(the_module, 0, expressions[749], 2); expressions[751] = BinaryenDrop(the_module, expressions[750]); expressions[752] = BinaryenConst(the_module, BinaryenLiteralInt32(1)); expressions[753] = BinaryenLoad(the_module, 4, 0, 0, 0, 2, expressions[752]); diff --git a/test/example/c-api-relooper-unreachable-if.cpp b/test/example/c-api-relooper-unreachable-if.cpp index 3b35221ec..329b0e3b7 100644 --- a/test/example/c-api-relooper-unreachable-if.cpp +++ b/test/example/c-api-relooper-unreachable-if.cpp @@ -242,7 +242,8 @@ int main() { expressions[76] = BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[75]); expressions[77] = BinaryenConst(the_module, BinaryenLiteralInt32(128)); expressions[78] = BinaryenBinary(the_module, 1, expressions[76], expressions[77]); - expressions[79] = BinaryenLocalTee(the_module, 3, expressions[78]); + expressions[79] = + BinaryenLocalTee(the_module, 3, expressions[78], BinaryenTypeInt32()); expressions[80] = BinaryenStore( the_module, 4, 0, 0, expressions[75], expressions[79], BinaryenTypeInt32()); expressions[81] = BinaryenLocalGet(the_module, 3, BinaryenTypeInt32()); @@ -333,7 +334,8 @@ int main() { expressions[123] = BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[122]); expressions[124] = BinaryenConst(the_module, BinaryenLiteralInt32(128)); expressions[125] = BinaryenBinary(the_module, 1, expressions[123], expressions[124]); - expressions[126] = BinaryenLocalTee(the_module, 5, expressions[125]); + expressions[126] = + BinaryenLocalTee(the_module, 5, expressions[125], BinaryenTypeInt32()); expressions[127] = BinaryenStore(the_module, 4, 0, @@ -497,7 +499,8 @@ int main() { expressions[186] = BinaryenLoad(the_module, 4, 0, 0, 0, BinaryenTypeInt32(), expressions[185]); expressions[187] = BinaryenConst(the_module, BinaryenLiteralInt32(128)); expressions[188] = BinaryenBinary(the_module, 1, expressions[186], expressions[187]); - expressions[189] = BinaryenLocalTee(the_module, 6, expressions[188]); + expressions[189] = + BinaryenLocalTee(the_module, 6, expressions[188], BinaryenTypeInt32()); expressions[190] = BinaryenStore(the_module, 4, 0, |