x86_64: fix packed struct equality

Closes #22990
This commit is contained in:
Jacob Young 2025-05-31 23:39:35 -04:00 committed by mlugg
parent 9edfccb9a7
commit 6daa37ded9
No known key found for this signature in database
GPG Key ID: 3F5B7DCCBF4AF02E
2 changed files with 29 additions and 2 deletions

View File

@ -77309,11 +77309,27 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
},
}
},
.int => res[0] = ops[0].cmpInts(cmp_op, &ops[1], cg) catch |err| break :err err,
.int => {
switch (ty.zigTypeTag(zcu)) {
else => {},
.@"struct", .@"union" => {
assert(ty.containerLayout(zcu) == .@"packed");
for (&ops) |*op| op.wrapInt(cg) catch |err| switch (err) {
error.SelectFailed => return cg.fail("failed to select {s} wrap {} {}", .{
@tagName(air_tag),
ty.fmt(pt),
op.tracking(cg),
}),
else => |e| return e,
};
},
}
res[0] = ops[0].cmpInts(cmp_op, &ops[1], cg) catch |err| break :err err;
},
}) catch |err| switch (err) {
error.SelectFailed => return cg.fail("failed to select {s} {} {} {}", .{
@tagName(air_tag),
cg.typeOf(bin_op.lhs).fmt(pt),
ty.fmt(pt),
ops[0].tracking(cg),
ops[1].tracking(cg),
}),

View File

@ -1307,6 +1307,17 @@ test "packed struct equality" {
comptime try S.doTest(x, y);
}
test "packed struct equality ignores padding bits" {
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
const S = packed struct { b: bool };
var s: S = undefined;
s.b = true;
try std.testing.expect(s != S{ .b = false });
try std.testing.expect(s == S{ .b = true });
}
test "packed struct with signed field" {
var s: packed struct {
a: i2,