zir: use node union field for alloc_inferred

Previously we used `un_node` and passed `undefined` for the operand, but
this causes illegal behavior when printing ZIR code.
This commit is contained in:
Andrew Kelley 2021-04-07 11:34:23 -07:00
parent 4e8fb9e6a5
commit d9c25ec672
3 changed files with 7 additions and 7 deletions

View File

@ -1484,7 +1484,7 @@ fn varDecl(
init_scope.rl_ptr = try init_scope.addUnNode(.alloc, type_inst, node);
init_scope.rl_ty_inst = type_inst;
} else {
const alloc = try init_scope.addUnNode(.alloc_inferred, undefined, node);
const alloc = try init_scope.addNode(.alloc_inferred, node);
resolve_inferred_alloc = alloc;
init_scope.rl_ptr = alloc;
}
@ -1559,7 +1559,7 @@ fn varDecl(
const alloc = try gz.addUnNode(.alloc_mut, type_inst, node);
break :a .{ .alloc = alloc, .result_loc = .{ .ptr = alloc } };
} else a: {
const alloc = try gz.addUnNode(.alloc_inferred_mut, undefined, node);
const alloc = try gz.addNode(.alloc_inferred_mut, node);
resolve_inferred_alloc = alloc;
break :a .{ .alloc = alloc, .result_loc = .{ .inferred_ptr = alloc } };
};

View File

@ -785,8 +785,8 @@ fn zirAllocInferred(
const tracy = trace(@src());
defer tracy.end();
const inst_data = sema.code.instructions.items(.data)[inst].un_node;
const src = inst_data.src();
const src_node = sema.code.instructions.items(.data)[inst].node;
const src: LazySrcLoc = .{ .node_offset = src_node };
const val_payload = try sema.arena.create(Value.Payload.InferredAlloc);
val_payload.* = .{

View File

@ -130,7 +130,7 @@ pub const Inst = struct {
/// Same as `alloc` except mutable.
alloc_mut,
/// Same as `alloc` except the type is inferred.
/// The operand is unused.
/// Uses the `node` union field.
alloc_inferred,
/// Same as `alloc_inferred` except mutable.
alloc_inferred_mut,
@ -1577,8 +1577,6 @@ const Writer = struct {
.alloc,
.alloc_mut,
.alloc_inferred,
.alloc_inferred_mut,
.indexable_ptr_len,
.bit_not,
.bool_not,
@ -1745,6 +1743,8 @@ const Writer = struct {
.ret_type,
.repeat,
.repeat_inline,
.alloc_inferred,
.alloc_inferred_mut,
=> try self.writeNode(stream, inst),
.error_value,