Skip to content

Commit 1feaaf1

Browse files
committed
x86_64: fix packedStore miscomp by spilling EFLAGS
Fixes ziglang#20113 and ziglang#20581. AND instructions in packedStore clobbers EFLAGS. Bug: ziglang#20113 Bug: ziglang#20581 Signed-off-by: Bingwu Zhang <[email protected]>
1 parent 1f92b39 commit 1feaaf1

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/arch/x86_64/CodeGen.zig

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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 });

0 commit comments

Comments
 (0)