Skip to content

Commit

Permalink
AstGen: always add dbg_block_end before last instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexu committed Mar 18, 2022
1 parent 3a6f467 commit a917b10
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/AstGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6155,11 +6155,11 @@ fn switchExpr(
}
const case_result = try expr(&case_scope, sub_scope, block_scope.break_result_loc, case.ast.target_expr);
try checkUsed(parent_gz, &case_scope.base, sub_scope);
try case_scope.addDbgBlockEnd();
if (!parent_gz.refIsNoReturn(case_result)) {
block_scope.break_count += 1;
_ = try case_scope.addBreak(.@"break", switch_block, case_result);
}
try case_scope.addDbgBlockEnd();

const case_slice = case_scope.instructionsSlice();
payloads.items[body_len_index] = @intCast(u32, case_slice.len);
Expand Down Expand Up @@ -10874,18 +10874,22 @@ const GenZir = struct {

fn addDbgBlockEnd(gz: *GenZir) !void {
if (gz.force_comptime) return;
const gpa = gz.astgen.gpa;

if (gz.endsWithNoReturn()) {
const last = gz.instructions.pop();
_ = try gz.add(.{ .tag = .extended, .data = .{
.extended = .{ .opcode = .dbg_block_end, .small = undefined, .operand = undefined },
} });
try gz.instructions.append(gz.astgen.gpa, last);
} else {
_ = try gz.add(.{ .tag = .extended, .data = .{
.extended = .{ .opcode = .dbg_block_end, .small = undefined, .operand = undefined },
} });
const tags = gz.astgen.instructions.items(.tag);
const data = gz.astgen.instructions.items(.data);
const last_inst = gz.instructions.items[gz.instructions.items.len - 1];
// remove dbg_block_begin immediately followed by dbg_block_end
if (tags[last_inst] == .extended and data[last_inst].extended.opcode == .dbg_block_begin) {
_ = gz.instructions.pop();
return;
}

const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
try gz.astgen.instructions.append(gpa, .{ .tag = .extended, .data = .{
.extended = .{ .opcode = .dbg_block_end, .small = undefined, .operand = undefined },
} });
try gz.instructions.insert(gpa, gz.instructions.items.len - 1, new_index);
}

/// Control flow does not fall through the "then" block of a loop; it continues
Expand Down
2 changes: 2 additions & 0 deletions test/behavior/struct.zig
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ test "packed struct 24bits" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
if (builtin.cpu.arch == .wasm32) return error.SkipZigTest; // TODO
if (builtin.cpu.arch == .arm) return error.SkipZigTest; // TODO

comptime {
try expect(@sizeOf(Foo24Bits) == 4);
Expand Down Expand Up @@ -979,6 +980,7 @@ test "tuple assigned to variable" {

test "comptime struct field" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
if (builtin.stage2_arch == .arm) return error.SkipZigTest; // TODO

const T = struct {
a: i32,
Expand Down

0 comments on commit a917b10

Please sign in to comment.