Commit e39c86399d

Andrew Kelley <andrew@ziglang.org>
2022-03-30 05:08:28
link: half-hearted bug fix for decl_state field
The init()/commit() API of this field leads to the type of bug that this commit fixes by defering an uncomfortably complex expression. I didn't bother doing the equivalent fix in link/MachO.zig because instead I think the `decl_state` field should be entirely removed from Dwarf.
1 parent b59428e
Changed files (2)
src/link/Dwarf.zig
@@ -91,7 +91,7 @@ pub const DeclState = struct {
         };
     }
 
-    fn deinit(self: *DeclState, gpa: Allocator) void {
+    pub fn deinit(self: *DeclState, gpa: Allocator) void {
         self.dbg_line.deinit();
         self.dbg_info.deinit();
         self.abbrev_type_arena.deinit();
src/link/Elf.zig
@@ -2342,6 +2342,12 @@ pub fn updateFunc(self: *Elf, module: *Module, func: *Module.Fn, air: Air, liven
     if (self.dwarf) |*dw| {
         try dw.initDeclState(decl);
     }
+    defer if (self.dwarf) |*dw| {
+        if (dw.decl_state) |*ds| {
+            ds.deinit(dw.allocator);
+            dw.decl_state = null;
+        }
+    };
 
     const res = if (self.dwarf) |*dw|
         try codegen.generateFunction(&self.base, decl.srcLoc(), func, air, liveness, &code_buffer, .{