llvm: fix switch loop on larger than pointer integer
This commit is contained in:
committed by
Jacob Young
parent
f34b4780b7
commit
687370237f
@@ -6050,10 +6050,10 @@ pub const FuncGen = struct {
|
|||||||
const target_blocks = dispatch_info.case_blocks[0..target_blocks_len];
|
const target_blocks = dispatch_info.case_blocks[0..target_blocks_len];
|
||||||
|
|
||||||
// Make sure to cast the index to a usize so it's not treated as negative!
|
// Make sure to cast the index to a usize so it's not treated as negative!
|
||||||
const table_index = try self.wip.cast(
|
const table_index = try self.wip.conv(
|
||||||
.zext,
|
.unsigned,
|
||||||
try self.wip.bin(.@"sub nuw", cond, jmp_table.min.toValue(), ""),
|
try self.wip.bin(.@"sub nuw", cond, jmp_table.min.toValue(), ""),
|
||||||
try o.lowerType(pt, Type.usize),
|
try o.lowerType(pt, .usize),
|
||||||
"",
|
"",
|
||||||
);
|
);
|
||||||
const target_ptr_ptr = try self.wip.gep(
|
const target_ptr_ptr = try self.wip.gep(
|
||||||
|
|||||||
@@ -226,3 +226,28 @@ test "unanalyzed continue with operand" {
|
|||||||
true => {},
|
true => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "switch loop on larger than pointer integer" {
|
||||||
|
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
||||||
|
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
|
||||||
|
if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
|
||||||
|
|
||||||
|
var entry: @Type(.{ .int = .{
|
||||||
|
.signedness = .unsigned,
|
||||||
|
.bits = @bitSizeOf(usize) + 1,
|
||||||
|
} }) = undefined;
|
||||||
|
entry = 0;
|
||||||
|
loop: switch (entry) {
|
||||||
|
0 => {
|
||||||
|
entry += 1;
|
||||||
|
continue :loop 1;
|
||||||
|
},
|
||||||
|
1 => |x| {
|
||||||
|
entry += 1;
|
||||||
|
continue :loop x + 1;
|
||||||
|
},
|
||||||
|
2 => entry += 1,
|
||||||
|
else => unreachable,
|
||||||
|
}
|
||||||
|
try expect(entry == 3);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user