Skip to content

Commit

Permalink
Zir: handle ranges in getMultiProng
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexu committed Oct 5, 2022
1 parent c0350cf commit 4057865
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Zir.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3051,11 +3051,16 @@ pub const Inst = struct {
var multi_i: u32 = 0;
while (true) : (multi_i += 1) {
const items_len = zir.extra[extra_index];
extra_index += 2;
extra_index += 1;
const ranges_len = zir.extra[extra_index];
extra_index += 1;
const body_len = @truncate(u31, zir.extra[extra_index]);
extra_index += 1;
const items = zir.refSlice(extra_index, items_len);
extra_index += items_len;
// Each range has a start and an end.
extra_index += 2 * ranges_len;

const body = zir.extra[extra_index..][0..body_len];
extra_index += body_len;

Expand Down
1 change: 1 addition & 0 deletions test/behavior.zig
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ test {
_ = @import("behavior/bugs/12801-1.zig");
_ = @import("behavior/bugs/12801-2.zig");
_ = @import("behavior/bugs/12885.zig");
_ = @import("behavior/bugs/12890.zig");
_ = @import("behavior/bugs/12911.zig");
_ = @import("behavior/bugs/12928.zig");
_ = @import("behavior/bugs/12945.zig");
Expand Down
18 changes: 18 additions & 0 deletions test/behavior/bugs/12890.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const expect = @import("std").testing.expect;
const builtin = @import("builtin");

fn a(b: []u3, c: u3) void {
switch (c) {
0...1 => b[c] = c,
2...3 => b[c] = c,
4...7 => |d| b[d] = c,
}
}
test {
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO

var arr: [8]u3 = undefined;
a(&arr, 5);
try expect(arr[5] == 5);
}

0 comments on commit 4057865

Please sign in to comment.