authorgravatar for alichraghi@proton.meAli Chraghi <alichraghi@proton.me> 2023-10-31 17:40:56+03:30
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-11-01 19:04:21-04:00
log3ead829de191daa0bb4047aa4dfde3b1902e5cd2
tree4ac25201b888a1aebc4b8a6a68bdfde370ae2d19
parentc2cf47ab28dc8b0cf3ef5b06c2ac69db622dcff4

print_zir: fix crash in writeRestoreErrRetIndex


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

src/print_zir.zig+17-11
......@@ -33,7 +33,7 @@ pub fn renderAsTextToFile(
3333 const stream = raw_stream.writer();
3434
3535 const main_struct_inst: Zir.Inst.Index = .main_struct_inst;
36 try stream.print("%{d} ", .{main_struct_inst});
36 try stream.print("%{d} ", .{@intFromEnum(main_struct_inst)});
3737 try writer.writeInstToStream(stream, main_struct_inst);
3838 try stream.writeAll("\n");
3939 const imports_index = scope_file.zir.extra[@intFromEnum(Zir.ExtraIndex.imports)];
......@@ -85,7 +85,7 @@ pub fn renderInstructionContext(
8585
8686 try writer.writeBody(stream, block[0..block_index]);
8787 try stream.writeByteNTimes(' ', writer.indent - 2);
88 try stream.print("> %{d} ", .{block[block_index]});
88 try stream.print("> %{d} ", .{@intFromEnum(block[block_index])});
8989 try writer.writeInstToStream(stream, block[block_index]);
9090 try stream.writeByte('\n');
9191 if (block_index + 1 < block.len) {
......@@ -115,7 +115,7 @@ pub fn renderSingleInstruction(
115115 .recurse_blocks = false,
116116 };
117117
118 try stream.print("%{d} ", .{inst});
118 try stream.print("%{d} ", .{@intFromEnum(inst)});
119119 try writer.writeInstToStream(stream, inst);
120120}
121121
......@@ -1811,7 +1811,7 @@ const Writer = struct {
18111811 if (self.recurse_decls) {
18121812 const tag = self.code.instructions.items(.tag)[@intFromEnum(decl_index)];
18131813 try stream.print(" line({d}) hash({}): %{d} = {s}(", .{
1814 line, std.fmt.fmtSliceHexLower(&hash_bytes), decl_index, @tagName(tag),
1814 line, std.fmt.fmtSliceHexLower(&hash_bytes), @intFromEnum(decl_index), @tagName(tag),
18151815 });
18161816
18171817 const decl_block_inst_data = self.code.instructions.items(.data)[@intFromEnum(decl_index)].pl_node;
......@@ -1823,7 +1823,7 @@ const Writer = struct {
18231823 try stream.writeAll("\n");
18241824 } else {
18251825 try stream.print(" line({d}) hash({}): %{d} = ...\n", .{
1826 line, std.fmt.fmtSliceHexLower(&hash_bytes), decl_index,
1826 line, std.fmt.fmtSliceHexLower(&hash_bytes), @intFromEnum(decl_index),
18271827 });
18281828 }
18291829 }
......@@ -2462,9 +2462,15 @@ const Writer = struct {
24622462 fn writeRestoreErrRetIndex(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
24632463 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].restore_err_ret_index;
24642464
2465 try self.writeInstRef(stream, inst_data.block);
2466 try stream.writeAll(", ");
2467 try self.writeInstRef(stream, inst_data.operand);
2465 if (inst_data.block != .none) {
2466 try self.writeInstRef(stream, inst_data.block);
2467 }
2468
2469 if (inst_data.operand != .none) {
2470 if (inst_data.block != .none) try stream.writeAll(", ");
2471 try self.writeInstRef(stream, inst_data.operand);
2472 }
2473
24682474 try stream.writeAll(")");
24692475 }
24702476
......@@ -2613,13 +2619,13 @@ const Writer = struct {
26132619 return self.writeInstIndex(stream, i);
26142620 } else {
26152621 const val: InternPool.Index = @enumFromInt(@intFromEnum(ref));
2616 return stream.print("@{}", .{val});
2622 return stream.print("@{s}", .{@tagName(val)});
26172623 }
26182624 }
26192625
26202626 fn writeInstIndex(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
26212627 _ = self;
2622 return stream.print("%{d}", .{inst});
2628 return stream.print("%{d}", .{@intFromEnum(inst)});
26232629 }
26242630
26252631 fn writeOptionalInstRef(
......@@ -2738,7 +2744,7 @@ const Writer = struct {
27382744 fn writeBody(self: *Writer, stream: anytype, body: []const Zir.Inst.Index) !void {
27392745 for (body) |inst| {
27402746 try stream.writeByteNTimes(' ', self.indent);
2741 try stream.print("%{d} ", .{inst});
2747 try stream.print("%{d} ", .{@intFromEnum(inst)});
27422748 try self.writeInstToStream(stream, inst);
27432749 try stream.writeByte('\n');
27442750 }