authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-10-15 18:56:58+02:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-10-16 15:54:17+02:00
log6fcd72355cac1495c213da20a6cf4f6f30bd2a65
tree227d979fb5516aadc3225b692666123a1998d3fa
parente62bb1d6892e0ca4afe921bee2eb8baa778b51b5
signature Commit is signed but in an unrecognized format.

wasm: correctly get the type of a local for free

When determining the type of a local (read: register), we would previously subtract the stack locals also. However, this locals are also within the same `locals` list, meaning the type of the local we were retrieving was off by 2. This could create a validation error when we re-use a local of a different type.

1 files changed, 2 insertions(+), 2 deletions(-)

src/arch/wasm/CodeGen.zig+2-2
......@@ -106,8 +106,8 @@ const WValue = union(enum) {
106106 fn free(value: *WValue, gen: *Self) void {
107107 if (value.* != .local) return;
108108 const local_value = value.local.value;
109 const reserved = gen.args.len + @boolToInt(gen.return_value != .none) + 2; // 2 for stack locals
110 if (local_value < reserved) return; // reserved locals may never be re-used.
109 const reserved = gen.args.len + @boolToInt(gen.return_value != .none);
110 if (local_value < reserved + 2) return; // reserved locals may never be re-used. Also accounts for 2 stack locals.
111111
112112 const index = local_value - reserved;
113113 const valtype = @intToEnum(wasm.Valtype, gen.locals.items[index]);