diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig index 6a6022b62d..90c777aa45 100644 --- 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 index aa6ec9db80..22031fe698 100644 --- 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")); +}