authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-08 18:19:48-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-08 18:19:48-07:00
logfd47839064775c0cc956f12a012f0893e1f3a440
tree230142a7a89e36ad5e7a6d9a4ef9c1434ec0e8ac
parent069a6f2432be5fd5e9a3eabd13faa43143001bbd

stage2: fix crash on empty source file


4 files changed, 20 insertions(+), 10 deletions(-)

src-self-hosted/Module.zig+3-5
......@@ -949,10 +949,8 @@ pub fn update(self: *Module) !void {
949949 try self.deleteDecl(decl);
950950 }
951951
952 if (self.totalErrorCount() == 0) {
953 // This is needed before reading the error flags.
954 try self.bin_file.flush();
955 }
952 // This is needed before reading the error flags.
953 try self.bin_file.flush();
956954
957955 self.link_error_flags = self.bin_file.errorFlags();
958956
......@@ -2537,7 +2535,7 @@ pub fn coerce(self: *Module, scope: *Scope, dest_type: Type, inst: *Inst) !*Inst
25372535 }
25382536 }
25392537
2540 return self.fail(scope, inst.src, "TODO implement type coercion from {} to {}", .{ inst.ty, dest_type });
2538 return self.fail(scope, inst.src, "expected {}, found {}", .{ dest_type, inst.ty });
25412539}
25422540
25432541pub fn storePtr(self: *Module, scope: *Scope, src: usize, ptr: *Inst, uncasted_value: *Inst) !*Inst {
src-self-hosted/link.zig+10-4
......@@ -1172,7 +1172,10 @@ pub const File = struct {
11721172
11731173 self.debug_aranges_section_dirty = false;
11741174 }
1175 if (self.debug_line_header_dirty) {
1175 if (self.debug_line_header_dirty) debug_line: {
1176 if (self.dbg_line_fn_first == null) {
1177 break :debug_line; // Error in module; leave debug_line_header_dirty=true.
1178 }
11761179 const dbg_line_prg_off = self.getDebugLineProgramOff();
11771180 const dbg_line_prg_end = self.getDebugLineProgramEnd();
11781181 assert(dbg_line_prg_end != 0);
......@@ -1403,18 +1406,21 @@ pub const File = struct {
14031406 self.shdr_table_dirty = false;
14041407 }
14051408 if (self.entry_addr == null and self.base.options.output_mode == .Exe) {
1406 log.debug(.link, "no_entry_point_found = true\n", .{});
1409 log.debug(.link, "flushing. no_entry_point_found = true\n", .{});
14071410 self.error_flags.no_entry_point_found = true;
14081411 } else {
1412 log.debug(.link, "flushing. no_entry_point_found = false\n", .{});
14091413 self.error_flags.no_entry_point_found = false;
14101414 try self.writeElfHeader();
14111415 }
14121416
1413 // The point of flush() is to commit changes, so nothing should be dirty after this.
1417 // The point of flush() is to commit changes, so in theory, nothing should
1418 // be dirty after this. However, it is possible for some things to remain
1419 // dirty because they fail to be written in the event of compile errors,
1420 // such as debug_line_header_dirty.
14141421 assert(!self.debug_info_section_dirty);
14151422 assert(!self.debug_abbrev_section_dirty);
14161423 assert(!self.debug_aranges_section_dirty);
1417 assert(!self.debug_line_header_dirty);
14181424 assert(!self.phdr_table_dirty);
14191425 assert(!self.shdr_table_dirty);
14201426 assert(!self.shstrtab_dirty);
src-self-hosted/main.zig+3
......@@ -64,6 +64,9 @@ var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){};
6464
6565pub fn main() !void {
6666 const gpa = if (std.builtin.link_libc) std.heap.c_allocator else &general_purpose_allocator.allocator;
67 defer if (!std.builtin.link_libc) {
68 _ = general_purpose_allocator.deinit();
69 };
6770 var arena_instance = std.heap.ArenaAllocator.init(gpa);
6871 defer arena_instance.deinit();
6972 const arena = &arena_instance.allocator;
test/stage2/compare_output.zig+4-1
......@@ -23,6 +23,9 @@ pub fn addCases(ctx: *TestContext) !void {
2323
2424 {
2525 var case = ctx.exe("hello world with updates", linux_x64);
26
27 case.addError("", &[_][]const u8{":1:1: error: no entry point found"});
28
2629 // Regular old hello world
2730 case.addCompareOutput(
2831 \\export fn _start() noreturn {
......@@ -123,7 +126,7 @@ pub fn addCases(ctx: *TestContext) !void {
123126 \\
124127 );
125128 }
126
129
127130 {
128131 var case = ctx.exe("hello world", linux_riscv64);
129132 // Regular old hello world