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 /src/ir | |
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 'src/ir')
-rw-r--r-- | src/ir/ExpressionManipulator.cpp | 2 | ||||
-rw-r--r-- | src/ir/localize.h | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/src/ir/ExpressionManipulator.cpp b/src/ir/ExpressionManipulator.cpp index fd0e6fd75..fbee9f9c1 100644 --- a/src/ir/ExpressionManipulator.cpp +++ b/src/ir/ExpressionManipulator.cpp @@ -91,7 +91,7 @@ flexibleCopy(Expression* original, Module& wasm, CustomCopier custom) { } Expression* visitLocalSet(LocalSet* curr) { if (curr->isTee()) { - return builder.makeLocalTee(curr->index, copy(curr->value)); + return builder.makeLocalTee(curr->index, copy(curr->value), curr->type); } else { return builder.makeLocalSet(curr->index, copy(curr->value)); } diff --git a/src/ir/localize.h b/src/ir/localize.h index ff454382d..733e7bdec 100644 --- a/src/ir/localize.h +++ b/src/ir/localize.h @@ -36,7 +36,7 @@ struct Localizer { index = set->index; } else { index = Builder::addVar(func, expr->type); - expr = Builder(*wasm).makeLocalTee(index, expr); + expr = Builder(*wasm).makeLocalTee(index, expr, expr->type); } } }; |