| author | |
| committer | |
| log | 687370237fdd80bf0693679cbc11598f14151f0a |
| tree | a050ac34480f02c83e97e43409c2f2b608d384f5 |
| parent | f34b4780b7bd52d14df253d0762d9c73db8eb226 |
2 files changed, 28 insertions(+), 3 deletions(-)
src/codegen/llvm.zig+3-3| ... | ... | @@ -6050,10 +6050,10 @@ pub const FuncGen = struct { |
| 6050 | 6050 | const target_blocks = dispatch_info.case_blocks[0..target_blocks_len]; |
| 6051 | 6051 | |
| 6052 | 6052 | // Make sure to cast the index to a usize so it's not treated as negative! |
| 6053 | const table_index = try self.wip.cast( | |
| 6054 | .zext, | |
| 6053 | const table_index = try self.wip.conv( | |
| 6054 | .unsigned, | |
| 6055 | 6055 | try self.wip.bin(.@"sub nuw", cond, jmp_table.min.toValue(), ""), |
| 6056 | try o.lowerType(pt, Type.usize), | |
| 6056 | try o.lowerType(pt, .usize), | |
| 6057 | 6057 | "", |
| 6058 | 6058 | ); |
| 6059 | 6059 | const target_ptr_ptr = try self.wip.gep( |
test/behavior/switch_loop.zig+25| ... | ... | @@ -226,3 +226,28 @@ test "unanalyzed continue with operand" { |
| 226 | 226 | true => {}, |
| 227 | 227 | } |
| 228 | 228 | } |
| 229 | ||
| 230 | test "switch loop on larger than pointer integer" { | |
| 231 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | |
| 232 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | |
| 233 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | |
| 234 | ||
| 235 | var entry: @Type(.{ .int = .{ | |
| 236 | .signedness = .unsigned, | |
| 237 | .bits = @bitSizeOf(usize) + 1, | |
| 238 | } }) = undefined; | |
| 239 | entry = 0; | |
| 240 | loop: switch (entry) { | |
| 241 | 0 => { | |
| 242 | entry += 1; | |
| 243 | continue :loop 1; | |
| 244 | }, | |
| 245 | 1 => |x| { | |
| 246 | entry += 1; | |
| 247 | continue :loop x + 1; | |
| 248 | }, | |
| 249 | 2 => entry += 1, | |
| 250 | else => unreachable, | |
| 251 | } | |
| 252 | try expect(entry == 3); | |
| 253 | } |