From a917b105a1140533f65fbb3f51b0d21723c4750d Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Sat, 19 Mar 2022 00:56:37 +0200 Subject: [PATCH] AstGen: always add dbg_block_end before last instruction --- src/AstGen.zig | 26 +++++++++++++++----------- test/behavior/struct.zig | 2 ++ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/AstGen.zig b/src/AstGen.zig index 76dc63032780..8e6540c980f5 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -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); @@ -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 diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig index da7d1d74206e..52116ec15882 100644 --- a/test/behavior/struct.zig +++ b/test/behavior/struct.zig @@ -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); @@ -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,