From 89d1cf92be0636a219ee6415eead387241963dcf Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Thu, 12 Dec 2019 18:36:31 -0800 Subject: 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`. --- src/binaryen-c.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/binaryen-c.cpp') diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index 35f394fd1..70712d4d4 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -1197,22 +1197,23 @@ BinaryenExpressionRef BinaryenLocalSet(BinaryenModuleRef module, ret->index = index; ret->value = (Expression*)value; - ret->setTee(false); + ret->makeSet(); ret->finalize(); return static_cast(ret); } BinaryenExpressionRef BinaryenLocalTee(BinaryenModuleRef module, BinaryenIndex index, - BinaryenExpressionRef value) { + BinaryenExpressionRef value, + BinaryenType type) { auto* ret = ((Module*)module)->allocator.alloc(); if (tracing) { - traceExpression(ret, "BinaryenLocalTee", index, value); + traceExpression(ret, "BinaryenLocalTee", index, value, type); } ret->index = index; ret->value = (Expression*)value; - ret->setTee(true); + ret->makeTee(Type(type)); ret->finalize(); return static_cast(ret); } -- cgit v1.2.3