diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-04-07 11:34:23 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-04-07 11:34:23 -0700 |
| commit | d9c25ec6720ecb0bc79fcab67659ee12ca6ad687 (patch) | |
| tree | 6ec9572a2d31ee93492a0746732308aa04b1a0dc /src | |
| parent | 4e8fb9e6a5f9a65bbf6469e386e83ba469e7543b (diff) | |
| download | zig-d9c25ec6720ecb0bc79fcab67659ee12ca6ad687.tar.gz zig-d9c25ec6720ecb0bc79fcab67659ee12ca6ad687.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/AstGen.zig | 4 | ||||
| -rw-r--r-- | src/Sema.zig | 4 | ||||
| -rw-r--r-- | src/zir.zig | 6 |
3 files changed, 7 insertions, 7 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig index af9938d425..d6c2eea5a3 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -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 } }; }; diff --git a/src/Sema.zig b/src/Sema.zig index 41544cdfe5..80b9ae37c9 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -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.* = .{ diff --git a/src/zir.zig b/src/zir.zig index 00ff23acb0..d3d9d56bfd 100644 --- a/src/zir.zig +++ b/src/zir.zig @@ -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, |
