Commit 057d97c093

Jakub Konka <kubkon@jakubkonka.com>
2020-06-02 19:05:21
Return should be i32 due to error signaling in memory.grow
Also, fix tests.
1 parent 3f0a3ce
Changed files (2)
src
test
stage1
behavior
src/ir.cpp
@@ -4997,7 +4997,7 @@ static IrInstSrc *ir_build_wasm_memory_size_src(IrBuilderSrc *irb, Scope *scope,
 static IrInstGen *ir_build_wasm_memory_size_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *index) {
     IrInstGenWasmMemorySize *instruction = ir_build_inst_gen<IrInstGenWasmMemorySize>(&ira->new_irb,
             source_instr->scope, source_instr->source_node);
-    instruction->base.value->type = ira->codegen->builtin_types.entry_u32;
+    instruction->base.value->type = ira->codegen->builtin_types.entry_i32;
     instruction->index = index;
 
     ir_ref_inst_gen(index);
@@ -5019,7 +5019,7 @@ static IrInstSrc *ir_build_wasm_memory_grow_src(IrBuilderSrc *irb, Scope *scope,
 static IrInstGen *ir_build_wasm_memory_grow_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *index, IrInstGen *delta) {
     IrInstGenWasmMemoryGrow *instruction = ir_build_inst_gen<IrInstGenWasmMemoryGrow>(&ira->new_irb,
             source_instr->scope, source_instr->source_node);
-    instruction->base.value->type = ira->codegen->builtin_types.entry_u32;
+    instruction->base.value->type = ira->codegen->builtin_types.entry_i32;
     instruction->index = index;
     instruction->delta = delta;
 
test/stage1/behavior/wasm.zig
@@ -2,7 +2,7 @@ const std = @import("std");
 const expect = std.testing.expect;
 
 test "memory size and grow" {
-    var prev = @wasmMemorySize();
-    expect(prev == @wasmMemoryGrow(1));
-    expect(prev + 1 == @wasmMemorySize());
+    var prev = @wasmMemorySize(0);
+    expect(prev == @wasmMemoryGrow(0, 1));
+    expect(prev + 1 == @wasmMemorySize(0));
 }