Zir: handle ranges in getMultiProng

Closes #12890
This commit is contained in:
Veikka Tuominen 2022-10-03 14:05:55 +03:00
parent c0350cf87e
commit 40578656e8
3 changed files with 25 additions and 1 deletions

View File

@ -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;

View File

@ -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");

View File

@ -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);
}