stage2: add missing asserts and early returns for LLVM backend

This commit is contained in:
Timon Kruiper 2020-12-24 11:40:54 +01:00
parent 6b8d28312c
commit 09cf043efd
2 changed files with 7 additions and 1 deletions

View File

@ -413,6 +413,8 @@ pub fn createEmpty(gpa: *Allocator, options: link.Options) !*Coff {
}
pub fn allocateDeclIndexes(self: *Coff, decl: *Module.Decl) !void {
if (self.llvm_ir_module) |_| return;
try self.offset_table.ensureCapacity(self.base.allocator, self.offset_table.items.len + 1);
if (self.offset_table_free_list.popOrNull()) |i| {
@ -710,6 +712,8 @@ pub fn updateDecl(self: *Coff, module: *Module, decl: *Module.Decl) !void {
}
pub fn freeDecl(self: *Coff, decl: *Module.Decl) void {
if (self.llvm_ir_module) |_| return;
// Appending to free lists is allowed to fail because the free lists are heuristics based anyway.
self.freeTextBlock(&decl.link.coff);
self.offset_table_free_list.append(self.base.allocator, decl.link.coff.offset_table_index) catch {};
@ -1245,6 +1249,7 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {
}
pub fn getDeclVAddr(self: *Coff, decl: *const Module.Decl) u64 {
assert(self.llvm_ir_module == null);
return self.text_section_virtual_address + decl.link.coff.text_offset;
}

View File

@ -318,6 +318,7 @@ pub fn deinit(self: *Elf) void {
}
pub fn getDeclVAddr(self: *Elf, decl: *const Module.Decl) u64 {
assert(self.llvm_ir_module == null);
assert(decl.link.elf.local_sym_index != 0);
return self.local_symbols.items[decl.link.elf.local_sym_index].st_value;
}
@ -437,7 +438,7 @@ fn updateString(self: *Elf, old_str_off: u32, new_name: []const u8) !u32 {
}
pub fn populateMissingMetadata(self: *Elf) !void {
if (self.llvm_ir_module) |_| return;
assert(self.llvm_ir_module == null);
const small_ptr = switch (self.ptr_width) {
.p32 => true,