diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-10-09 22:06:49 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-09 22:06:49 -0700 |
| commit | aaf46187ab7bf23c87a275e2755a9bd01f3c93cf (patch) | |
| tree | 7359cf8adeca3493e9e9865093ba68e0763d4ee1 /src/arch/wasm/CodeGen.zig | |
| parent | fa08e49f839d47441af9a1bcf23dc1701849379e (diff) | |
| parent | 703fe0f121df9df44721250528e508762e161780 (diff) | |
| download | zig-aaf46187ab7bf23c87a275e2755a9bd01f3c93cf.tar.gz zig-aaf46187ab7bf23c87a275e2755a9bd01f3c93cf.zip | |
Merge pull request #17391 from xxxbxxx/load-i4
codegen/llvm: truncate padding bits when loading a non-byte-sized value
Diffstat (limited to 'src/arch/wasm/CodeGen.zig')
| -rw-r--r-- | src/arch/wasm/CodeGen.zig | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index 922fc4db07..a898d18382 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 { |
