authorgravatar for xtex@astrafall.orgxtex <xtex@astrafall.org> 2025-03-16 08:51:53+08:00
committergravatar for xtex@astrafall.orgxtex <xtex@astrafall.org> 2025-03-22 16:06:07+08:00
logc62fb118e70faf531162b897d7e57df843229b72
tree545c2846224ddd208718d6f4607032529cdfd75a
parent9c9d3931df4c1decffec610e5e47b3049b147c8d
signaturelock-open Commit is signed but in an unrecognized format.

x86_64: fix packedStore miscomp by spilling EFLAGS

Fixes #20113 and #20581. AND instructions in packedStore clobbers EFLAGS. Bug: https://github.com/ziglang/zig/issues/20113 Bug: https://github.com/ziglang/zig/issues/20581 Signed-off-by: Bingwu Zhang <xtex@aosc.io>

1 files changed, 6 insertions(+), 3 deletions(-)

src/arch/x86_64/CodeGen.zig+6-3
......@@ -88178,12 +88178,15 @@ fn airStore(self: *CodeGen, inst: Air.Inst.Index, safety: bool) !void {
8817888178 const reg_locks = self.register_manager.lockRegsAssumeUnused(3, .{ .rdi, .rsi, .rcx });
8817988179 defer for (reg_locks) |lock| self.register_manager.unlockReg(lock);
8818088180
88181 const ptr_ty = self.typeOf(bin_op.lhs);
88182 const ptr_info = ptr_ty.ptrInfo(zcu);
88183 const is_packed = ptr_info.flags.vector_index != .none or ptr_info.packed_offset.host_size > 0;
88184 if (is_packed) try self.spillEflagsIfOccupied();
88185
8818188186 const src_mcv = try self.resolveInst(bin_op.rhs);
8818288187 const ptr_mcv = try self.resolveInst(bin_op.lhs);
88183 const ptr_ty = self.typeOf(bin_op.lhs);
8818488188
88185 const ptr_info = ptr_ty.ptrInfo(zcu);
88186 if (ptr_info.flags.vector_index != .none or ptr_info.packed_offset.host_size > 0) {
88189 if (is_packed) {
8818788190 try self.packedStore(ptr_ty, ptr_mcv, src_mcv);
8818888191 } else {
8818988192 try self.store(ptr_ty, ptr_mcv, src_mcv, .{ .safety = safety });