zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit c71bb0f2b66f72122e25400c97a1213d59e4ad73 (tree)
parent 24bfefa75e813af188e3fa43e473e495cc97ed43
Author: Jacob Young <jacobly0@users.noreply.github.com>
Date:   Thu, 19 Jun 2025 20:02:47 -0400

x86_64: fix pair live-out tracking

Closes #24226

Diffstat:
Msrc/arch/x86_64/CodeGen.zig | 1+
Mtest/behavior/slice.zig | 14++++++++++++++
2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig @@ -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 }, diff --git a/test/behavior/slice.zig b/test/behavior/slice.zig @@ -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")); +}