authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-24 22:45:10-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-24 22:45:10-07:00
log7f91be9c80f8d79e4a2c6cf0b15197cdd454cef6
tree3356aeb0462c236f4e9af621415ad4582ea4f832
parentbcf2eb1a003d076c166d4ce9cba20f6ed9b53887

AstGen: emit break_inline from inline while loop


2 files changed, 12 insertions(+), 2 deletions(-)

src/AstGen.zig+2-2
...@@ -1878,8 +1878,8 @@ fn continueExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index)...@@ -1878,8 +1878,8 @@ fn continueExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index)
1878 continue;1878 continue;
1879 }1879 }
18801880
1881 // TODO emit a break_inline if the loop being continued is inline1881 const break_tag: Zir.Inst.Tag = if (gen_zir.is_inline) .break_inline else .@"break";
1882 _ = try parent_gz.addBreak(.@"break", continue_block, .void_value);1882 _ = try parent_gz.addBreak(break_tag, continue_block, .void_value);
1883 return Zir.Inst.Ref.unreachable_value;1883 return Zir.Inst.Ref.unreachable_value;
1884 },1884 },
1885 .local_val => scope = scope.cast(Scope.LocalVal).?.parent,1885 .local_val => scope = scope.cast(Scope.LocalVal).?.parent,
test/behavior/while.zig+10
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const expect = std.testing.expect;3const expect = std.testing.expect;
4const assert = std.debug.assert;
45
5test "while loop" {6test "while loop" {
6 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;7 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
...@@ -326,3 +327,12 @@ test "while error 2 break statements and an else" {...@@ -326,3 +327,12 @@ test "while error 2 break statements and an else" {
326 try S.entry(true, false);327 try S.entry(true, false);
327 comptime try S.entry(true, false);328 comptime try S.entry(true, false);
328}329}
330
331test "continue inline while loop" {
332 comptime var i = 0;
333 inline while (i < 10) : (i += 1) {
334 if (i < 5) continue;
335 break;
336 }
337 comptime assert(i == 5);
338}