authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-03-19 00:56:37+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-03-19 11:20:38+02:00
log1e1f74034773e441e689036ef90fd5a451a9f9d1
treeb2f73773702cbe807a6a8ee261e5fd419ff089e2
parent30e17cd5d0f3d3cfea689c25c870a378c4a9053b

AstGen: always add dbg_block_end before last instruction


2 files changed, 17 insertions(+), 11 deletions(-)

src/AstGen.zig+15-11
......@@ -6152,11 +6152,11 @@ fn switchExpr(
61526152 }
61536153 const case_result = try expr(&case_scope, sub_scope, block_scope.break_result_loc, case.ast.target_expr);
61546154 try checkUsed(parent_gz, &case_scope.base, sub_scope);
6155 try case_scope.addDbgBlockEnd();
61556156 if (!parent_gz.refIsNoReturn(case_result)) {
61566157 block_scope.break_count += 1;
61576158 _ = try case_scope.addBreak(.@"break", switch_block, case_result);
61586159 }
6159 try case_scope.addDbgBlockEnd();
61606160
61616161 const case_slice = case_scope.instructionsSlice();
61626162 payloads.items[body_len_index] = @intCast(u32, case_slice.len);
......@@ -10871,18 +10871,22 @@ const GenZir = struct {
1087110871
1087210872 fn addDbgBlockEnd(gz: *GenZir) !void {
1087310873 if (gz.force_comptime) return;
10874 const gpa = gz.astgen.gpa;
1087410875
10875 if (gz.endsWithNoReturn()) {
10876 const last = gz.instructions.pop();
10877 _ = try gz.add(.{ .tag = .extended, .data = .{
10878 .extended = .{ .opcode = .dbg_block_end, .small = undefined, .operand = undefined },
10879 } });
10880 try gz.instructions.append(gz.astgen.gpa, last);
10881 } else {
10882 _ = try gz.add(.{ .tag = .extended, .data = .{
10883 .extended = .{ .opcode = .dbg_block_end, .small = undefined, .operand = undefined },
10884 } });
10876 const tags = gz.astgen.instructions.items(.tag);
10877 const data = gz.astgen.instructions.items(.data);
10878 const last_inst = gz.instructions.items[gz.instructions.items.len - 1];
10879 // remove dbg_block_begin immediately followed by dbg_block_end
10880 if (tags[last_inst] == .extended and data[last_inst].extended.opcode == .dbg_block_begin) {
10881 _ = gz.instructions.pop();
10882 return;
1088510883 }
10884
10885 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
10886 try gz.astgen.instructions.append(gpa, .{ .tag = .extended, .data = .{
10887 .extended = .{ .opcode = .dbg_block_end, .small = undefined, .operand = undefined },
10888 } });
10889 try gz.instructions.insert(gpa, gz.instructions.items.len - 1, new_index);
1088610890 }
1088710891
1088810892 /// Control flow does not fall through the "then" block of a loop; it continues
test/behavior/struct.zig+2
......@@ -427,6 +427,7 @@ test "packed struct 24bits" {
427427 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
428428 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
429429 if (builtin.cpu.arch == .wasm32) return error.SkipZigTest; // TODO
430 if (builtin.cpu.arch == .arm) return error.SkipZigTest; // TODO
430431
431432 comptime {
432433 try expect(@sizeOf(Foo24Bits) == 4);
......@@ -979,6 +980,7 @@ test "tuple assigned to variable" {
979980
980981test "comptime struct field" {
981982 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
983 if (builtin.stage2_arch == .arm) return error.SkipZigTest; // TODO
982984
983985 const T = struct {
984986 a: i32,