x86_64: fix packed struct field reuse

This commit is contained in:
Jacob Young 2023-12-04 13:31:34 -05:00
parent bdb6546a8f
commit c70c333594
2 changed files with 5 additions and 4 deletions

View File

@ -7324,8 +7324,8 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
.load_frame => |frame_addr| { .load_frame => |frame_addr| {
const field_abi_size: u32 = @intCast(field_ty.abiSize(mod)); const field_abi_size: u32 = @intCast(field_ty.abiSize(mod));
if (field_off % 8 == 0) { if (field_off % 8 == 0) {
const off_mcv = const field_byte_off = @divExact(field_off, 8);
src_mcv.address().offset(@intCast(@divExact(field_off, 8))).deref(); const off_mcv = src_mcv.address().offset(@intCast(field_byte_off)).deref();
const field_bit_size = field_ty.bitSize(mod); const field_bit_size = field_ty.bitSize(mod);
if (field_abi_size <= 8) { 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); 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 off_mcv
else dst: { else dst: {
const dst_mcv = try self.allocRegOrMem(inst, true); const dst_mcv = try self.allocRegOrMem(inst, true);

View File

@ -804,7 +804,6 @@ test "nested packed struct at non-zero offset" {
} }
test "nested packed struct at non-zero offset 2" { test "nested packed struct at non-zero offset 2" {
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO