authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-01-19 16:25:20-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-01-19 16:25:55-07:00
log072d1e088c3e383c2303b873f55399d374d9808c
tree80858b240c7b18873c25f3969f1f08100956bd76
parent1af31baf0ba447b6ea5a1456df5ba2d82dc26e56

stage2: fix anonymous Decl ty/val wrong arena

string literals and error set types were allocating the ty/val fields of the anonymous Decl into the owner Decl's arena, rather than the new anonymous Decl's arena as intended. This caused use of undefined value later on in the pipeline.

2 files changed, 7 insertions(+), 4 deletions(-)

src/Compilation.zig+1-1
......@@ -1552,7 +1552,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
15521552 // are lifetime annotations in the ZIR.
15531553 var decl_arena = decl.typed_value.most_recent.arena.?.promote(module.gpa);
15541554 defer decl.typed_value.most_recent.arena.?.* = decl_arena.state;
1555 log.debug("analyze liveness of {s}\n", .{decl.name});
1555 log.debug("analyze liveness of {s}", .{decl.name});
15561556 try liveness.analyze(module.gpa, &decl_arena.allocator, func.body);
15571557
15581558 if (std.builtin.mode == .Debug and self.verbose_ir) {
src/zir_sema.zig+6-3
......@@ -547,9 +547,12 @@ fn analyzeInstStr(mod: *Module, scope: *Scope, str_inst: *zir.Inst.Str) InnerErr
547547 errdefer new_decl_arena.deinit();
548548 const arena_bytes = try new_decl_arena.allocator.dupe(u8, str_inst.positionals.bytes);
549549
550 const decl_ty = try Type.Tag.array_u8_sentinel_0.create(&new_decl_arena.allocator, arena_bytes.len);
551 const decl_val = try Value.Tag.bytes.create(&new_decl_arena.allocator, arena_bytes);
552
550553 const new_decl = try mod.createAnonymousDecl(scope, &new_decl_arena, .{
551 .ty = try Type.Tag.array_u8_sentinel_0.create(scope.arena(), arena_bytes.len),
552 .val = try Value.Tag.bytes.create(scope.arena(), arena_bytes),
554 .ty = decl_ty,
555 .val = decl_val,
553556 });
554557 return mod.analyzeDeclRef(scope, str_inst.base.src, new_decl);
555558}
......@@ -1079,7 +1082,7 @@ fn analyzeInstErrorSet(mod: *Module, scope: *Scope, inst: *zir.Inst.ErrorSet) In
10791082 var new_decl_arena = std.heap.ArenaAllocator.init(mod.gpa);
10801083 errdefer new_decl_arena.deinit();
10811084
1082 const payload = try scope.arena().create(Value.Payload.ErrorSet);
1085 const payload = try new_decl_arena.allocator.create(Value.Payload.ErrorSet);
10831086 payload.* = .{
10841087 .base = .{ .tag = .error_set },
10851088 .data = .{