authorgravatar for topolarity@tapscott.meCody Tapscott <topolarity@tapscott.me> 2022-11-21 08:57:40-07:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-22 14:00:41+02:00
log3fa226a80c99dadab91538ef450b22230da9c21f
tree50027571a1e1e96315efca21e2713befe883b39f
parent283c92e3628a831b6be7d4ef79628b55ce8b6817

AstGen: Pop error trace for `continue`

PR #12837 handled control flow for break and return, but I forgot about `continue`. This is effectively another break, so we just need another `.restore_err_ret_index` ZIR instruction. Resolves #13618.

2 files changed, 56 insertions(+), 0 deletions(-)

src/AstGen.zig+5
......@@ -2071,6 +2071,11 @@ fn continueExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index)
20712071 if (break_tag == .break_inline) {
20722072 _ = try parent_gz.addUnNode(.check_comptime_control_flow, Zir.indexToRef(continue_block), node);
20732073 }
2074
2075 // As our last action before the continue, "pop" the error trace if needed
2076 if (!gen_zir.force_comptime)
2077 _ = try parent_gz.addRestoreErrRetIndex(.{ .block = continue_block }, .always);
2078
20742079 _ = try parent_gz.addBreak(break_tag, continue_block, .void_value);
20752080 return Zir.Inst.Ref.unreachable_value;
20762081 },
test/stack_traces.zig+51
......@@ -151,6 +151,57 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
151151 },
152152 });
153153
154 cases.addCase(.{
155 .name = "continue in while loop",
156 .source =
157 \\fn foo() !void {
158 \\ return error.UhOh;
159 \\}
160 \\
161 \\pub fn main() !void {
162 \\ var i: usize = 0;
163 \\ while (i < 3) : (i += 1) {
164 \\ foo() catch continue;
165 \\ }
166 \\ return error.UnrelatedError;
167 \\}
168 ,
169 .Debug = .{
170 .expect =
171 \\error: UnrelatedError
172 \\source.zig:10:5: [address] in main (test)
173 \\ return error.UnrelatedError;
174 \\ ^
175 \\
176 ,
177 },
178 .ReleaseSafe = .{
179 .exclude_os = .{
180 .windows, // TODO
181 .linux, // defeated by aggressive inlining
182 },
183 .expect =
184 \\error: UnrelatedError
185 \\source.zig:10:5: [address] in [function]
186 \\ return error.UnrelatedError;
187 \\ ^
188 \\
189 ,
190 },
191 .ReleaseFast = .{
192 .expect =
193 \\error: UnrelatedError
194 \\
195 ,
196 },
197 .ReleaseSmall = .{
198 .expect =
199 \\error: UnrelatedError
200 \\
201 ,
202 },
203 });
204
154205 cases.addCase(.{
155206 .name = "try return + handled catch/if-else",
156207 .source =