From 072d1e088c3e383c2303b873f55399d374d9808c Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 19 Jan 2021 16:25:20 -0700 Subject: [PATCH] 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. --- src/Compilation.zig | 2 +- src/zir_sema.zig | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Compilation.zig b/src/Compilation.zig index 7700fcdc4a..fae725a1ac 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1552,7 +1552,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor // are lifetime annotations in the ZIR. var decl_arena = decl.typed_value.most_recent.arena.?.promote(module.gpa); defer decl.typed_value.most_recent.arena.?.* = decl_arena.state; - log.debug("analyze liveness of {s}\n", .{decl.name}); + log.debug("analyze liveness of {s}", .{decl.name}); try liveness.analyze(module.gpa, &decl_arena.allocator, func.body); if (std.builtin.mode == .Debug and self.verbose_ir) { diff --git a/src/zir_sema.zig b/src/zir_sema.zig index b5b256afd3..0caaa2a03f 100644 --- a/src/zir_sema.zig +++ b/src/zir_sema.zig @@ -547,9 +547,12 @@ fn analyzeInstStr(mod: *Module, scope: *Scope, str_inst: *zir.Inst.Str) InnerErr errdefer new_decl_arena.deinit(); const arena_bytes = try new_decl_arena.allocator.dupe(u8, str_inst.positionals.bytes); + const decl_ty = try Type.Tag.array_u8_sentinel_0.create(&new_decl_arena.allocator, arena_bytes.len); + const decl_val = try Value.Tag.bytes.create(&new_decl_arena.allocator, arena_bytes); + const new_decl = try mod.createAnonymousDecl(scope, &new_decl_arena, .{ - .ty = try Type.Tag.array_u8_sentinel_0.create(scope.arena(), arena_bytes.len), - .val = try Value.Tag.bytes.create(scope.arena(), arena_bytes), + .ty = decl_ty, + .val = decl_val, }); return mod.analyzeDeclRef(scope, str_inst.base.src, new_decl); } @@ -1079,7 +1082,7 @@ fn analyzeInstErrorSet(mod: *Module, scope: *Scope, inst: *zir.Inst.ErrorSet) In var new_decl_arena = std.heap.ArenaAllocator.init(mod.gpa); errdefer new_decl_arena.deinit(); - const payload = try scope.arena().create(Value.Payload.ErrorSet); + const payload = try new_decl_arena.allocator.create(Value.Payload.ErrorSet); payload.* = .{ .base = .{ .tag = .error_set }, .data = .{