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...@@ -1552,7 +1552,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
1552 // are lifetime annotations in the ZIR.1552 // are lifetime annotations in the ZIR.
1553 var decl_arena = decl.typed_value.most_recent.arena.?.promote(module.gpa);1553 var decl_arena = decl.typed_value.most_recent.arena.?.promote(module.gpa);
1554 defer decl.typed_value.most_recent.arena.?.* = decl_arena.state;1554 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});
1556 try liveness.analyze(module.gpa, &decl_arena.allocator, func.body);1556 try liveness.analyze(module.gpa, &decl_arena.allocator, func.body);
15571557
1558 if (std.builtin.mode == .Debug and self.verbose_ir) {1558 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...@@ -547,9 +547,12 @@ fn analyzeInstStr(mod: *Module, scope: *Scope, str_inst: *zir.Inst.Str) InnerErr
547 errdefer new_decl_arena.deinit();547 errdefer new_decl_arena.deinit();
548 const arena_bytes = try new_decl_arena.allocator.dupe(u8, str_inst.positionals.bytes);548 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
550 const new_decl = try mod.createAnonymousDecl(scope, &new_decl_arena, .{553 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),554 .ty = decl_ty,
552 .val = try Value.Tag.bytes.create(scope.arena(), arena_bytes),555 .val = decl_val,
553 });556 });
554 return mod.analyzeDeclRef(scope, str_inst.base.src, new_decl);557 return mod.analyzeDeclRef(scope, str_inst.base.src, new_decl);
555}558}
...@@ -1079,7 +1082,7 @@ fn analyzeInstErrorSet(mod: *Module, scope: *Scope, inst: *zir.Inst.ErrorSet) In...@@ -1079,7 +1082,7 @@ fn analyzeInstErrorSet(mod: *Module, scope: *Scope, inst: *zir.Inst.ErrorSet) In
1079 var new_decl_arena = std.heap.ArenaAllocator.init(mod.gpa);1082 var new_decl_arena = std.heap.ArenaAllocator.init(mod.gpa);
1080 errdefer new_decl_arena.deinit();1083 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);
1083 payload.* = .{1086 payload.* = .{
1084 .base = .{ .tag = .error_set },1087 .base = .{ .tag = .error_set },
1085 .data = .{1088 .data = .{