diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2023-12-04 13:31:34 -0500 |
|---|---|---|
| committer | Jacob Young <jacobly0@users.noreply.github.com> | 2023-12-04 13:31:54 -0500 |
| commit | c70c33359498bfe33a2f60cfcc5ea401a277d5bf (patch) | |
| tree | 8c63d76b33589df5aaa418b9c3ebc37dece594e8 /src/arch/x86_64/CodeGen.zig | |
| parent | bdb6546a8f753fff65790fd289e35b1d5ba6cd5b (diff) | |
| download | zig-c70c33359498bfe33a2f60cfcc5ea401a277d5bf.tar.gz zig-c70c33359498bfe33a2f60cfcc5ea401a277d5bf.zip | |
x86_64: fix packed struct field reuse
Diffstat (limited to 'src/arch/x86_64/CodeGen.zig')
| -rw-r--r-- | src/arch/x86_64/CodeGen.zig | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig index e1cc9470cb..0a4c9844dc 100644 --- a/src/arch/x86_64/CodeGen.zig +++ b/src/arch/x86_64/CodeGen.zig @@ -7324,8 +7324,8 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void { .load_frame => |frame_addr| { const field_abi_size: u32 = @intCast(field_ty.abiSize(mod)); if (field_off % 8 == 0) { - const off_mcv = - src_mcv.address().offset(@intCast(@divExact(field_off, 8))).deref(); + const field_byte_off = @divExact(field_off, 8); + const off_mcv = src_mcv.address().offset(@intCast(field_byte_off)).deref(); const field_bit_size = field_ty.bitSize(mod); if (field_abi_size <= 8) { @@ -7350,7 +7350,9 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void { try self.copyToRegisterWithInstTracking(inst, field_ty, dst_mcv); } - const dst_mcv = if (self.reuseOperand(inst, operand, 0, src_mcv)) + const container_abi_size: u32 = @intCast(container_ty.abiSize(mod)); + const dst_mcv = if (field_byte_off + field_abi_size <= container_abi_size and + self.reuseOperand(inst, operand, 0, src_mcv)) off_mcv else dst: { const dst_mcv = try self.allocRegOrMem(inst, true); |
