x86_64: fix pair live-out tracking

Closes #24226
This commit is contained in:
Jacob Young 2025-06-19 20:02:47 -04:00 committed by Andrew Kelley
parent 24bfefa75e
commit c71bb0f2b6
2 changed files with 15 additions and 0 deletions

View File

@ -803,6 +803,7 @@ const InstTracking = struct {
remaining_reg = tracked_reg;
};
assert(found_reg);
if (tracking.long == .none) tracking.long = tracking.short;
tracking.short = switch (remaining_reg) {
.none => .{ .dead = function.scope_generation },
else => .{ .register = remaining_reg },

View File

@ -1079,3 +1079,17 @@ test "sentinel expression in slice operation has result type" {
comptime assert(slice[0] == 1);
comptime assert(slice[1] == 2);
}
test "conditionally return second argument slice" {
if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
const S = struct {
fn foo(cond: bool, slice: []const u8) []const u8 {
if (cond) return slice;
return &.{};
}
};
try expectEqualStrings("", S.foo(false, "false"));
try expectEqualStrings("true", S.foo(true, "true"));
}