aboutsummaryrefslogtreecommitdiff
path: root/src/arch/wasm/CodeGen.zig
diff options
context:
space:
mode:
authorLuuk de Gram <luuk@degram.dev>2022-10-15 18:56:58 +0200
committerLuuk de Gram <luuk@degram.dev>2022-10-16 15:54:17 +0200
commit6fcd72355cac1495c213da20a6cf4f6f30bd2a65 (patch)
tree227d979fb5516aadc3225b692666123a1998d3fa /src/arch/wasm/CodeGen.zig
parente62bb1d6892e0ca4afe921bee2eb8baa778b51b5 (diff)
downloadzig-6fcd72355cac1495c213da20a6cf4f6f30bd2a65.tar.gz
zig-6fcd72355cac1495c213da20a6cf4f6f30bd2a65.zip
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.
Diffstat (limited to 'src/arch/wasm/CodeGen.zig')
-rw-r--r--src/arch/wasm/CodeGen.zig4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig
index a614f07561..1b498f76cb 100644
--- a/src/arch/wasm/CodeGen.zig
+++ b/src/arch/wasm/CodeGen.zig
@@ -106,8 +106,8 @@ const WValue = union(enum) {
fn free(value: *WValue, gen: *Self) void {
if (value.* != .local) return;
const local_value = value.local.value;
- const reserved = gen.args.len + @boolToInt(gen.return_value != .none) + 2; // 2 for stack locals
- if (local_value < reserved) return; // reserved locals may never be re-used.
+ const reserved = gen.args.len + @boolToInt(gen.return_value != .none);
+ if (local_value < reserved + 2) return; // reserved locals may never be re-used. Also accounts for 2 stack locals.
const index = local_value - reserved;
const valtype = @intToEnum(wasm.Valtype, gen.locals.items[index]);