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.
This commit is contained in:
Andrew Kelley 2022-03-29 20:08:28 -07:00
parent b59428e9f7
commit e39c86399d
2 changed files with 7 additions and 1 deletions

View File

@ -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();

View File

@ -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, .{