Skip to content

x86_64: fix pair live-out tracking #24228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/arch/x86_64/CodeGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,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 },
Expand Down
14 changes: 14 additions & 0 deletions test/behavior/slice.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}