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(...@@ -6152,11 +6152,11 @@ fn switchExpr(
6152 }6152 }
6153 const case_result = try expr(&case_scope, sub_scope, block_scope.break_result_loc, case.ast.target_expr);6153 const case_result = try expr(&case_scope, sub_scope, block_scope.break_result_loc, case.ast.target_expr);
6154 try checkUsed(parent_gz, &case_scope.base, sub_scope);6154 try checkUsed(parent_gz, &case_scope.base, sub_scope);
6155 try case_scope.addDbgBlockEnd();
6155 if (!parent_gz.refIsNoReturn(case_result)) {6156 if (!parent_gz.refIsNoReturn(case_result)) {
6156 block_scope.break_count += 1;6157 block_scope.break_count += 1;
6157 _ = try case_scope.addBreak(.@"break", switch_block, case_result);6158 _ = try case_scope.addBreak(.@"break", switch_block, case_result);
6158 }6159 }
6159 try case_scope.addDbgBlockEnd();
61606160
6161 const case_slice = case_scope.instructionsSlice();6161 const case_slice = case_scope.instructionsSlice();
6162 payloads.items[body_len_index] = @intCast(u32, case_slice.len);6162 payloads.items[body_len_index] = @intCast(u32, case_slice.len);
...@@ -10871,18 +10871,22 @@ const GenZir = struct {...@@ -10871,18 +10871,22 @@ const GenZir = struct {
1087110871
10872 fn addDbgBlockEnd(gz: *GenZir) !void {10872 fn addDbgBlockEnd(gz: *GenZir) !void {
10873 if (gz.force_comptime) return;10873 if (gz.force_comptime) return;
10874 const gpa = gz.astgen.gpa;
1087410875
10875 if (gz.endsWithNoReturn()) {10876 const tags = gz.astgen.instructions.items(.tag);
10876 const last = gz.instructions.pop();10877 const data = gz.astgen.instructions.items(.data);
10877 _ = try gz.add(.{ .tag = .extended, .data = .{10878 const last_inst = gz.instructions.items[gz.instructions.items.len - 1];
10878 .extended = .{ .opcode = .dbg_block_end, .small = undefined, .operand = undefined },10879 // remove dbg_block_begin immediately followed by dbg_block_end
10879 } });10880 if (tags[last_inst] == .extended and data[last_inst].extended.opcode == .dbg_block_begin) {
10880 try gz.instructions.append(gz.astgen.gpa, last);10881 _ = gz.instructions.pop();
10881 } else {10882 return;
10882 _ = try gz.add(.{ .tag = .extended, .data = .{
10883 .extended = .{ .opcode = .dbg_block_end, .small = undefined, .operand = undefined },
10884 } });
10885 }10883 }
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);
10886 }10890 }
1088710891
10888 /// Control flow does not fall through the "then" block of a loop; it continues10892 /// 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" {...@@ -427,6 +427,7 @@ test "packed struct 24bits" {
427 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO427 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
428 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO428 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
429 if (builtin.cpu.arch == .wasm32) return error.SkipZigTest; // TODO429 if (builtin.cpu.arch == .wasm32) return error.SkipZigTest; // TODO
430 if (builtin.cpu.arch == .arm) return error.SkipZigTest; // TODO
430431
431 comptime {432 comptime {
432 try expect(@sizeOf(Foo24Bits) == 4);433 try expect(@sizeOf(Foo24Bits) == 4);
...@@ -979,6 +980,7 @@ test "tuple assigned to variable" {...@@ -979,6 +980,7 @@ test "tuple assigned to variable" {
979980
980test "comptime struct field" {981test "comptime struct field" {
981 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO982 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
983 if (builtin.stage2_arch == .arm) return error.SkipZigTest; // TODO
982984
983 const T = struct {985 const T = struct {
984 a: i32,986 a: i32,