aboutsummaryrefslogtreecommitdiff
path: root/src/arch/wasm/CodeGen.zig
diff options
context:
space:
mode:
authorXavier Bouchoux <xavierb@gmail.com>2023-10-08 11:10:27 +0200
committerXavier Bouchoux <xavierb@gmail.com>2023-10-08 11:37:49 +0200
commit85315bb535a98cb08b4eb8bad6254ef3f5d9714f (patch)
treea67dfef7804df7718368f09288be664fc31adcc6 /src/arch/wasm/CodeGen.zig
parentc86ba0f9d0d6d1421c93fa09a5172c796110258b (diff)
downloadzig-85315bb535a98cb08b4eb8bad6254ef3f5d9714f.tar.gz
zig-85315bb535a98cb08b4eb8bad6254ef3f5d9714f.zip
codegen/wasm: fix intcast accross 32-bits boundary
Diffstat (limited to 'src/arch/wasm/CodeGen.zig')
-rw-r--r--src/arch/wasm/CodeGen.zig16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig
index 49754f03f6..f382a7770c 100644
--- a/src/arch/wasm/CodeGen.zig
+++ b/src/arch/wasm/CodeGen.zig
@@ -4353,9 +4353,21 @@ fn intcast(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro
if (op_bits > 32 and op_bits <= 64 and wanted_bits == 32) {
try func.emitWValue(operand);
try func.addTag(.i32_wrap_i64);
+ if (given.isSignedInt(mod) and wanted_bitsize < 32)
+ return func.wrapOperand(.{ .stack = {} }, wanted)
+ else
+ return WValue{ .stack = {} };
} else if (op_bits == 32 and wanted_bits > 32 and wanted_bits <= 64) {
- try func.emitWValue(operand);
+ const operand32 = if (given_bitsize < 32 and wanted.isSignedInt(mod))
+ try func.signExtendInt(operand, given)
+ else
+ operand;
+ try func.emitWValue(operand32);
try func.addTag(if (wanted.isSignedInt(mod)) .i64_extend_i32_s else .i64_extend_i32_u);
+ if (given.isSignedInt(mod) and wanted_bitsize < 64)
+ return func.wrapOperand(.{ .stack = {} }, wanted)
+ else
+ return WValue{ .stack = {} };
} else if (wanted_bits == 128) {
// for 128bit integers we store the integer in the virtual stack, rather than a local
const stack_ptr = try func.allocStack(wanted);
@@ -4381,8 +4393,6 @@ fn intcast(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro
}
return stack_ptr;
} else return func.load(operand, wanted, 0);
-
- return WValue{ .stack = {} };
}
fn airIsNull(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode, op_kind: enum { value, ptr }) InnerError!void {