Commit c71bb0f2b6
Changed files (2)
src
arch
x86_64
test
behavior
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 },
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"));
+}