authorgravatar for timonkruiper@gmail.comTimon Kruiper <timonkruiper@gmail.com> 2020-12-24 11:40:54+01:00
committergravatar for timonkruiper@gmail.comTimon Kruiper <timonkruiper@gmail.com> 2020-12-28 21:20:49+01:00
log09cf043efd5966e328e4454bc30bc756f439938b
treebce231f261ec7a240aab48ffbd7fc65e89084811
parent6b8d28312ccca56d652af32bad360e9a5394fb8e

stage2: add missing asserts and early returns for LLVM backend


2 files changed, 7 insertions(+), 1 deletions(-)

src/link/Coff.zig+5
...@@ -413,6 +413,8 @@ pub fn createEmpty(gpa: *Allocator, options: link.Options) !*Coff {...@@ -413,6 +413,8 @@ pub fn createEmpty(gpa: *Allocator, options: link.Options) !*Coff {
413}413}
414414
415pub fn allocateDeclIndexes(self: *Coff, decl: *Module.Decl) !void {415pub fn allocateDeclIndexes(self: *Coff, decl: *Module.Decl) !void {
416 if (self.llvm_ir_module) |_| return;
417
416 try self.offset_table.ensureCapacity(self.base.allocator, self.offset_table.items.len + 1);418 try self.offset_table.ensureCapacity(self.base.allocator, self.offset_table.items.len + 1);
417419
418 if (self.offset_table_free_list.popOrNull()) |i| {420 if (self.offset_table_free_list.popOrNull()) |i| {
...@@ -710,6 +712,8 @@ pub fn updateDecl(self: *Coff, module: *Module, decl: *Module.Decl) !void {...@@ -710,6 +712,8 @@ pub fn updateDecl(self: *Coff, module: *Module, decl: *Module.Decl) !void {
710}712}
711713
712pub fn freeDecl(self: *Coff, decl: *Module.Decl) void {714pub fn freeDecl(self: *Coff, decl: *Module.Decl) void {
715 if (self.llvm_ir_module) |_| return;
716
713 // Appending to free lists is allowed to fail because the free lists are heuristics based anyway.717 // Appending to free lists is allowed to fail because the free lists are heuristics based anyway.
714 self.freeTextBlock(&decl.link.coff);718 self.freeTextBlock(&decl.link.coff);
715 self.offset_table_free_list.append(self.base.allocator, decl.link.coff.offset_table_index) catch {};719 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 {...@@ -1245,6 +1249,7 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {
1245}1249}
12461250
1247pub fn getDeclVAddr(self: *Coff, decl: *const Module.Decl) u64 {1251pub fn getDeclVAddr(self: *Coff, decl: *const Module.Decl) u64 {
1252 assert(self.llvm_ir_module == null);
1248 return self.text_section_virtual_address + decl.link.coff.text_offset;1253 return self.text_section_virtual_address + decl.link.coff.text_offset;
1249}1254}
12501255
src/link/Elf.zig+2-1
...@@ -318,6 +318,7 @@ pub fn deinit(self: *Elf) void {...@@ -318,6 +318,7 @@ pub fn deinit(self: *Elf) void {
318}318}
319319
320pub fn getDeclVAddr(self: *Elf, decl: *const Module.Decl) u64 {320pub fn getDeclVAddr(self: *Elf, decl: *const Module.Decl) u64 {
321 assert(self.llvm_ir_module == null);
321 assert(decl.link.elf.local_sym_index != 0);322 assert(decl.link.elf.local_sym_index != 0);
322 return self.local_symbols.items[decl.link.elf.local_sym_index].st_value;323 return self.local_symbols.items[decl.link.elf.local_sym_index].st_value;
323}324}
...@@ -437,7 +438,7 @@ fn updateString(self: *Elf, old_str_off: u32, new_name: []const u8) !u32 {...@@ -437,7 +438,7 @@ fn updateString(self: *Elf, old_str_off: u32, new_name: []const u8) !u32 {
437}438}
438439
439pub fn populateMissingMetadata(self: *Elf) !void {440pub fn populateMissingMetadata(self: *Elf) !void {
440 if (self.llvm_ir_module) |_| return;441 assert(self.llvm_ir_module == null);
441442
442 const small_ptr = switch (self.ptr_width) {443 const small_ptr = switch (self.ptr_width) {
443 .p32 => true,444 .p32 => true,